@@ -1247,26 +1247,28 @@ These are not used in annotations. They are building blocks for declaring types.
1247
1247
1248
1248
assert Point2D(x=1, y=2, label='first') == dict(x=1, y=2, label='first')
1249
1249
1250
- The type info for introspection can be accessed via ``Point2D.__annotations__ ``
1251
- and ``Point2D.__total__ ``. To allow using this feature with older versions
1252
- of Python that do not support :pep: `526 `, ``TypedDict `` supports two additional
1253
- equivalent syntactic forms::
1250
+ The type info for introspection can be accessed via ``Point2D.__annotations__ ``,
1251
+ ``Point2D.__total__ ``, ``Point2D.__required_keys__ ``, and
1252
+ ``Point2D.__optional_keys__ ``.
1253
+ To allow using this feature with older versions of Python that do not
1254
+ support :pep: `526 `, ``TypedDict `` supports two additional equivalent
1255
+ syntactic forms::
1254
1256
1255
1257
Point2D = TypedDict('Point2D', x=int, y=int, label=str)
1256
1258
Point2D = TypedDict('Point2D', {'x': int, 'y': int, 'label': str})
1257
1259
1258
- By default, all keys must be present in a TypedDict. It is possible
1259
- to override this by specifying totality.
1260
+ By default, all keys must be present in a `` TypedDict `` . It is possible to
1261
+ override this by specifying totality.
1260
1262
Usage::
1261
1263
1262
- class point2D (TypedDict, total=False):
1264
+ class Point2D (TypedDict, total=False):
1263
1265
x: int
1264
1266
y: int
1265
1267
1266
- This means that a point2D TypedDict can have any of the keys omitted. A type
1267
- checker is only expected to support a literal False or True as the value of
1268
- the total argument. True is the default, and makes all items defined in the
1269
- class body be required.
1268
+ This means that a `` Point2D `` `` TypedDict `` can have any of the keys
1269
+ omitted. A type checker is only expected to support a literal `` False `` or
1270
+ `` True `` as the value of the `` total `` argument. `` True `` is the default,
1271
+ and makes all items defined in the class body required.
1270
1272
1271
1273
See :pep: `589 ` for more examples and detailed rules of using ``TypedDict ``.
1272
1274
@@ -1980,4 +1982,3 @@ Constant
1980
1982
(see :pep: `563 `).
1981
1983
1982
1984
.. versionadded :: 3.5.2
1983
-
0 commit comments