summaryrefslogtreecommitdiffstats
path: root/Lib/typing.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/typing.py')
-rw-r--r--Lib/typing.py19
1 files changed, 17 insertions, 2 deletions
diff --git a/Lib/typing.py b/Lib/typing.py
index 570cb80..1dd9398 100644
--- a/Lib/typing.py
+++ b/Lib/typing.py
@@ -2908,7 +2908,7 @@ class _TypedDictMeta(type):
__instancecheck__ = __subclasscheck__
-def TypedDict(typename, fields=None, /, *, total=True):
+def TypedDict(typename, fields=_sentinel, /, *, total=True):
"""A simple typed namespace. At runtime it is equivalent to a plain dict.
TypedDict creates a dictionary type such that a type checker will expect all
@@ -2955,7 +2955,22 @@ def TypedDict(typename, fields=None, /, *, total=True):
See PEP 655 for more details on Required and NotRequired.
"""
- if fields is None:
+ if fields is _sentinel or fields is None:
+ import warnings
+
+ if fields is _sentinel:
+ deprecated_thing = "Failing to pass a value for the 'fields' parameter"
+ else:
+ deprecated_thing = "Passing `None` as the 'fields' parameter"
+
+ example = f"`{typename} = TypedDict({typename!r}, {{{{}}}})`"
+ deprecation_msg = (
+ "{name} is deprecated and will be disallowed in Python {remove}. "
+ "To create a TypedDict class with 0 fields "
+ "using the functional syntax, "
+ "pass an empty dictionary, e.g. "
+ ) + example + "."
+ warnings._deprecated(deprecated_thing, message=deprecation_msg, remove=(3, 15))
fields = {}
ns = {'__annotations__': dict(fields)}