summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorananthan-123 <ananthakrishnan15.2001@gmail.com>2020-02-19 04:33:05 (GMT)
committerGitHub <noreply@github.com>2020-02-19 04:33:05 (GMT)
commitab6423fe2de0ed5f8a0dc86a9c7070229326b0f0 (patch)
treef3906601d6712af51a19f3771886add951b491ca /Lib
parenta4ba8a3983356fceb4aedabe0c338180666a79aa (diff)
downloadcpython-ab6423fe2de0ed5f8a0dc86a9c7070229326b0f0.zip
cpython-ab6423fe2de0ed5f8a0dc86a9c7070229326b0f0.tar.gz
cpython-ab6423fe2de0ed5f8a0dc86a9c7070229326b0f0.tar.bz2
bpo-39572: Document ’total’ flag of TypedDict (GH-18554)
Diffstat (limited to 'Lib')
-rw-r--r--Lib/typing.py15
1 files changed, 14 insertions, 1 deletions
diff --git a/Lib/typing.py b/Lib/typing.py
index 6da145f..0a685d3 100644
--- a/Lib/typing.py
+++ b/Lib/typing.py
@@ -13,7 +13,7 @@ At large scale, the structure of the module is following:
* Public helper functions: get_type_hints, overload, cast, no_type_check,
no_type_check_decorator.
* Generic aliases for collections.abc ABCs and few additional protocols.
-* Special types: NewType, NamedTuple, TypedDict (may be added soon).
+* Special types: NewType, NamedTuple, TypedDict.
* Wrapper submodules for re and io related types.
"""
@@ -1885,6 +1885,19 @@ class TypedDict(dict, metaclass=_TypedDictMeta):
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
+ to override this by specifying totality.
+ Usage::
+
+ class point2D(TypedDict, total=False):
+ x: int
+ y: int
+
+ 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, 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+
"""