Skip to content

Commit ff93a63

Browse files
committed
Add docs
1 parent 5db07e2 commit ff93a63

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

HISTORY.md

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Our backwards-compatibility policy can be found [here](https://github.com/python
1919
- Add a [Migrations](https://catt.rs/en/latest/migrations.html) page, with instructions on migrating changed behavior for each version.
2020
([#577](https://github.com/python-attrs/cattrs/pull/577))
2121
- [`typing.Self`](https://docs.python.org/3/library/typing.html#typing.Self) is now supported in _attrs_ classes, dataclasses, TypedDicts and the dict NamedTuple factories.
22+
See [`typing.Self`](https://catt.rs/en/latest/defaulthooks.html#typing-self) for details.
2223
([#299](https://github.com/python-attrs/cattrs/issues/299) [#627](https://github.com/python-attrs/cattrs/pull/627))
2324
- Expose {func}`cattrs.cols.mapping_unstructure_factory` through {mod}`cattrs.cols`.
2425
- Some `defaultdicts` are now [supported by default](https://catt.rs/en/latest/defaulthooks.html#defaultdicts), and

docs/defaulthooks.md

+14
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,20 @@ Protocols are unstructured according to the actual runtime type of the value.
662662
Attributes annotated using [the Self type](https://docs.python.org/3/library/typing.html#typing.Self) are supported in _attrs_ classes, dataclasses, TypedDicts and NamedTuples
663663
(when using [the dict un/structure factories](customizing.md#customizing-named-tuples)).
664664

665+
```{doctest}
666+
>>> from typing import Self
667+
668+
>>> @define
669+
... class LinkedListNode:
670+
... element: int
671+
... next: Self | None = None
672+
673+
>>> cattrs.unstructure(LinkedListNode(1, LinkedListNode(2, None)))
674+
{'element': 1, 'next': {'element': 2, 'next': None}}
675+
>>> cattrs.structure({'element': 1, 'next': {'element': 2, 'next': None}}, LinkedListNode)
676+
LinkedListNode(element=1, next=LinkedListNode(element=2, next=None))
677+
```
678+
665679
```{note}
666680
Attributes annotated with `typing.Self` are not supported by the BaseConverter, as this is too complex for it.
667681
```

0 commit comments

Comments
 (0)