diff options
author | 97littleleaf11 <11172084+97littleleaf11@users.noreply.github.com> | 2022-02-17 03:26:07 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-17 03:26:07 (GMT) |
commit | de6043e596492201cc1a1eb28038970bb69f3107 (patch) | |
tree | de508de7d1a35ac82d227e4754186e5d93bc8901 /Doc/library/typing.rst | |
parent | 6f1efd19a70839d480e4b1fcd9fecd3a8725824b (diff) | |
download | cpython-de6043e596492201cc1a1eb28038970bb69f3107.zip cpython-de6043e596492201cc1a1eb28038970bb69f3107.tar.gz cpython-de6043e596492201cc1a1eb28038970bb69f3107.tar.bz2 |
bpo-46066: Deprecate kwargs syntax for TypedDict definitions (GH-31126)
Closes python/typing#981
https://bugs.python.org/issue46066
Diffstat (limited to 'Doc/library/typing.rst')
-rw-r--r-- | Doc/library/typing.rst | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/Doc/library/typing.rst b/Doc/library/typing.rst index 94a46b0..8240c91 100644 --- a/Doc/library/typing.rst +++ b/Doc/library/typing.rst @@ -1470,11 +1470,20 @@ These are not used in annotations. They are building blocks for declaring types. ``Point2D.__optional_keys__``. To allow using this feature with older versions of Python that do not support :pep:`526`, ``TypedDict`` supports two additional equivalent - syntactic forms:: + syntactic forms: + + * Using a literal :class:`dict` as the second argument:: - Point2D = TypedDict('Point2D', x=int, y=int, label=str) Point2D = TypedDict('Point2D', {'x': int, 'y': int, 'label': str}) + * Using keyword arguments:: + + Point2D = TypedDict('Point2D', x=int, y=int, label=str) + + .. deprecated-removed:: 3.11 3.13 + The keyword-argument syntax is deprecated in 3.11 and will be removed + in 3.13. It may also be unsupported by static type checkers. + By default, all keys must be present in a ``TypedDict``. It is possible to override this by specifying totality. Usage:: @@ -1483,6 +1492,9 @@ These are not used in annotations. They are building blocks for declaring types. x: int y: int + # Alternative syntax + Point2D = TypedDict('Point2D', {'x': int, 'y': int}, total=False) + This means that a ``Point2D`` ``TypedDict`` can have any of the keys omitted. A type checker is only expected to support a literal ``False`` or ``True`` as the value of the ``total`` argument. ``True`` is the default, |