Skip to content

Commit

Permalink
Add note to TypedDict.__total__docs
Browse files Browse the repository at this point in the history
As discussed in comments to python#109544, the semantics of this attribute
are somewhat confusing. Add a note explaining its limitations and
steering users towards __required_keys__ and __optional_keys__ instead.
  • Loading branch information
JelleZijlstra committed Sep 18, 2023
1 parent 0bb0d88 commit afd8037
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Doc/library/typing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2404,6 +2404,13 @@ types.
>>> Point3D.__total__
True

This attribute reflects *only* the value of the ``total`` argument
to the current ``TypedDict`` class, not whether the class is semantically
total. For example, a ``TypedDict`` with ``__total__`` set to True may
have keys marked with :data:`NotRequired`, or it may inherit from another
``TypedDict`` with ``total=False``. Therefore, it is generally better to use
:attr:`__required_keys__` and :attr:`__optional_keys__` for introspection.

.. attribute:: __required_keys__

.. versionadded:: 3.9
Expand Down

0 comments on commit afd8037

Please sign in to comment.