@@ -259,6 +259,13 @@ Special typing primitives
259
259
260
260
.. versionadded :: 4.12.0
261
261
262
+ .. data :: NoExtraItems
263
+
264
+ A sentinel used when the ``extra_items `` class argument to :class: `TypedDict ` is not
265
+ provided. In ``typing `` since 3.15.
266
+
267
+ .. versionadded :: 4.13.0
268
+
262
269
.. data :: NotRequired
263
270
264
271
See :py:data: `typing.NotRequired ` and :pep: `655 `. In ``typing `` since 3.11.
@@ -387,12 +394,13 @@ Special typing primitives
387
394
388
395
.. versionadded :: 4.10.0
389
396
390
- .. class :: TypedDict(dict, total=True)
391
-
392
- See :py:class: `typing.TypedDict ` and :pep: `589 `. In ``typing `` since 3.8.
397
+ .. class :: TypedDict(dict, total=True, closed=False, extra_items=<no extra items>)
393
398
399
+ See :py:class: `typing.TypedDict ` and :pep: `589 `. In ``typing `` since 3.8, but
400
+ changed and enhanced in several ways since then.
394
401
``typing_extensions `` backports various bug fixes and improvements
395
- to ``TypedDict `` on Python 3.11 and lower.
402
+ to ``TypedDict ``.
403
+
396
404
:py:class: `TypedDict ` does not store runtime information
397
405
about which (if any) keys are non-required in Python 3.8, and does not
398
406
honor the ``total `` keyword with old-style ``TypedDict() `` in Python
@@ -426,35 +434,23 @@ Special typing primitives
426
434
427
435
.. versionadded :: 4.9.0
428
436
429
- The experimental ``closed `` keyword argument and the special key
430
- ``__extra_items__ `` proposed in :pep: `728 ` are supported.
431
-
432
- When ``closed `` is unspecified or ``closed=False `` is given,
433
- ``__extra_items__ `` behaves like a regular key. Otherwise, this becomes a
434
- special key that does not show up in ``__readonly_keys__ ``,
435
- ``__mutable_keys__ ``, ``__required_keys__ ``, ``__optional_keys ``, or
436
- ``__annotations__ ``.
437
+ The ``closed `` and ``extra_items `` keyword arguments introduced by
438
+ :pep: `728 ` and supported in Python 3.15 and newer are supported.
437
439
438
440
For runtime introspection, two attributes can be looked at:
439
441
440
442
.. attribute :: __closed__
441
443
442
444
A boolean flag indicating whether the current ``TypedDict `` is
443
- considered closed. This is not inherited by the ``TypedDict ``'s
444
- subclasses.
445
+ considered closed. This reflects the ``closed `` class argument.
445
446
446
447
.. versionadded :: 4.10.0
447
448
448
449
.. attribute :: __extra_items__
449
450
450
- The type annotation of the extra items allowed on the ``TypedDict ``.
451
- This attribute defaults to ``None `` on a TypedDict that has itself and
452
- all its bases non-closed. This default is different from ``type(None) ``
453
- that represents ``__extra_items__: None `` defined on a closed
454
- ``TypedDict ``.
455
-
456
- If ``__extra_items__ `` is not defined or inherited on a closed
457
- ``TypedDict ``, this defaults to ``Never ``.
451
+ The type of the extra items allowed on the ``TypedDict ``.
452
+ This attribute defaults to :data: `NoExtraItems ` if the ``extra_items ``
453
+ class argument is not provided.
458
454
459
455
.. versionadded :: 4.10.0
460
456
@@ -495,6 +491,16 @@ Special typing primitives
495
491
The keyword argument ``closed `` and the special key ``__extra_items__ ``
496
492
when ``closed=True `` is given were supported.
497
493
494
+ .. versionchanged :: 4.13.0
495
+
496
+ :pep: `728 ` support was updated to a newer version. Extra items are now
497
+ indicated with an ``extra_items `` class argument, not a special key
498
+ ``__extra_items__ ``.
499
+
500
+ A value assigned to ``__total__ `` in the class body of a
501
+ ``TypedDict `` will be overwritten by the ``total `` argument of the
502
+ ``TypedDict `` constructor.
503
+
498
504
.. class :: TypeVar(name, *constraints, bound=None, covariant=False,
499
505
contravariant=False, infer_variance=False, default=NoDefault)
500
506
0 commit comments