Skip to content

Commit

Permalink
docs/defaulthooks: add note on TypedDict Required/NotRequired with `f…
Browse files Browse the repository at this point in the history
…rom __future__ import annotations` (#620)

Fix #619.
  • Loading branch information
bluetech authored Jan 7, 2025
1 parent f4a7385 commit 77f3c75
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions docs/defaulthooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,11 @@ Generic TypedDicts work on Python 3.11 and later, since that is the first Python

[`typing.Required` and `typing.NotRequired`](https://peps.python.org/pep-0655/) are supported.

:::{caution}
If `from __future__ import annotations` is used or if annotations are given as strings, `Required` and `NotRequired` are ignored by cattrs.
See [note in the Python documentation](https://docs.python.org/3/library/typing.html#typing.TypedDict.__optional_keys__).
:::

[Similar to _attrs_ classes](customizing.md#using-cattrsgen-hook-factories), un/structuring can be customized using {meth}`cattrs.gen.typeddicts.make_dict_structure_fn` and {meth}`cattrs.gen.typeddicts.make_dict_unstructure_fn`.

```{doctest}
Expand Down

0 comments on commit 77f3c75

Please sign in to comment.