summaryrefslogtreecommitdiffstats
path: root/Lib/typing.py
diff options
context:
space:
mode:
author97littleleaf11 <11172084+97littleleaf11@users.noreply.github.com>2022-02-17 03:26:07 (GMT)
committerGitHub <noreply@github.com>2022-02-17 03:26:07 (GMT)
commitde6043e596492201cc1a1eb28038970bb69f3107 (patch)
treede508de7d1a35ac82d227e4754186e5d93bc8901 /Lib/typing.py
parent6f1efd19a70839d480e4b1fcd9fecd3a8725824b (diff)
downloadcpython-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 'Lib/typing.py')
-rw-r--r--Lib/typing.py15
1 files changed, 11 insertions, 4 deletions
diff --git a/Lib/typing.py b/Lib/typing.py
index 4a8bdf8..3233827 100644
--- a/Lib/typing.py
+++ b/Lib/typing.py
@@ -2569,9 +2569,8 @@ def TypedDict(typename, fields=None, /, *, total=True, **kwargs):
The type info can be accessed via the Point2D.__annotations__ dict, and
the Point2D.__required_keys__ and Point2D.__optional_keys__ frozensets.
- TypedDict supports two additional equivalent forms::
+ TypedDict supports an additional equivalent form::
- Point2D = TypedDict('Point2D', x=int, y=int, label=str)
Point2D = TypedDict('Point2D', {'x': int, 'y': int, 'label': str})
By default, all keys must be present in a TypedDict. It is possible
@@ -2587,14 +2586,22 @@ def TypedDict(typename, fields=None, /, *, total=True, **kwargs):
the total argument. True is the default, and makes all items defined in the
class body be required.
- The class syntax is only supported in Python 3.6+, while two other
- syntax forms work for Python 2.7 and 3.2+
+ The class syntax is only supported in Python 3.6+, while the other
+ syntax form works for Python 2.7 and 3.2+
"""
if fields is None:
fields = kwargs
elif kwargs:
raise TypeError("TypedDict takes either a dict or keyword arguments,"
" but not both")
+ if kwargs:
+ warnings.warn(
+ "The kwargs-based syntax for TypedDict definitions is deprecated "
+ "in Python 3.11, will be removed in Python 3.13, and may not be "
+ "understood by third-party type checkers.",
+ DeprecationWarning,
+ stacklevel=2,
+ )
ns = {'__annotations__': dict(fields)}
module = _caller()