diff options
author | ananthan-123 <ananthakrishnan15.2001@gmail.com> | 2020-02-19 04:33:05 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-19 04:33:05 (GMT) |
commit | ab6423fe2de0ed5f8a0dc86a9c7070229326b0f0 (patch) | |
tree | f3906601d6712af51a19f3771886add951b491ca /Doc | |
parent | a4ba8a3983356fceb4aedabe0c338180666a79aa (diff) | |
download | cpython-ab6423fe2de0ed5f8a0dc86a9c7070229326b0f0.zip cpython-ab6423fe2de0ed5f8a0dc86a9c7070229326b0f0.tar.gz cpython-ab6423fe2de0ed5f8a0dc86a9c7070229326b0f0.tar.bz2 |
bpo-39572: Document ’total’ flag of TypedDict (GH-18554)
Diffstat (limited to 'Doc')
-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 d3bab94..eac75ee 100644 --- a/Doc/library/typing.rst +++ b/Doc/library/typing.rst @@ -996,8 +996,20 @@ The module defines the following classes, functions and decorators: Point2D = TypedDict('Point2D', x=int, y=int, label=str) Point2D = TypedDict('Point2D', {'x': int, 'y': int, 'label': str}) - See :pep:`589` for more examples and detailed rules of using ``TypedDict`` - with type checkers. + 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. + + See :pep:`589` for more examples and detailed rules of using ``TypedDict``. .. versionadded:: 3.8 |