Skip to content

Commit 8897584

Browse files
Update TypedDict docs (#664)
1 parent c8caace commit 8897584

File tree

1 file changed

+28
-22
lines changed

1 file changed

+28
-22
lines changed

doc/index.rst

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,13 @@ Special typing primitives
259259

260260
.. versionadded:: 4.12.0
261261

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+
262269
.. data:: NotRequired
263270

264271
See :py:data:`typing.NotRequired` and :pep:`655`. In ``typing`` since 3.11.
@@ -387,12 +394,13 @@ Special typing primitives
387394

388395
.. versionadded:: 4.10.0
389396

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>)
393398

399+
See :py:class:`typing.TypedDict` and :pep:`589`. In ``typing`` since 3.8, but
400+
changed and enhanced in several ways since then.
394401
``typing_extensions`` backports various bug fixes and improvements
395-
to ``TypedDict`` on Python 3.11 and lower.
402+
to ``TypedDict``.
403+
396404
:py:class:`TypedDict` does not store runtime information
397405
about which (if any) keys are non-required in Python 3.8, and does not
398406
honor the ``total`` keyword with old-style ``TypedDict()`` in Python
@@ -426,35 +434,23 @@ Special typing primitives
426434

427435
.. versionadded:: 4.9.0
428436

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.
437439

438440
For runtime introspection, two attributes can be looked at:
439441

440442
.. attribute:: __closed__
441443

442444
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.
445446

446447
.. versionadded:: 4.10.0
447448

448449
.. attribute:: __extra_items__
449450

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.
458454

459455
.. versionadded:: 4.10.0
460456

@@ -495,6 +491,16 @@ Special typing primitives
495491
The keyword argument ``closed`` and the special key ``__extra_items__``
496492
when ``closed=True`` is given were supported.
497493

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+
498504
.. class:: TypeVar(name, *constraints, bound=None, covariant=False,
499505
contravariant=False, infer_variance=False, default=NoDefault)
500506

0 commit comments

Comments
 (0)