From 4c8180d8655b19fef4d56769a99e0b9b26df0d74 Mon Sep 17 00:00:00 2001 From: AN Long Date: Mon, 12 Jan 2026 00:53:25 +0900 Subject: [PATCH] gh-86139: Correct NamedTuple and TypedDict's type in typing.rst (GH-143692) (cherry picked from commit e22b68568a30e65358f6036e4d0e5505d0f76fcb) Co-authored-by: AN Long Co-authored-by: Alex Waygood --- Doc/library/typing.rst | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/Doc/library/typing.rst b/Doc/library/typing.rst index febabb5bb6d031..4384707dc39907 100644 --- a/Doc/library/typing.rst +++ b/Doc/library/typing.rst @@ -2257,7 +2257,7 @@ These functions and classes should not be used directly as annotations. Their intended purpose is to be building blocks for creating and declaring types. -.. class:: NamedTuple +.. function:: NamedTuple Typed version of :func:`collections.namedtuple`. @@ -2330,6 +2330,10 @@ types. Removed the ``_field_types`` attribute in favor of the more standard ``__annotations__`` attribute which has the same information. + .. versionchanged:: 3.9 + ``NamedTuple`` is now a function rather than a class. + It can still be used as a class base, as described above. + .. versionchanged:: 3.11 Added support for generic namedtuples. @@ -2482,10 +2486,10 @@ types. for more details. -.. class:: TypedDict(dict) +.. function:: TypedDict Special construct to add type hints to a dictionary. - At runtime it is a plain :class:`dict`. + At runtime ":class:`!TypedDict` instances" are simply :class:`dicts `. ``TypedDict`` declares a dictionary type that expects all of its instances to have a certain set of keys, where each key is @@ -2708,6 +2712,10 @@ types. .. versionadded:: 3.8 + .. versionchanged:: 3.9 + ``TypedDict`` is now a function rather than a class. + It can still be used as a class base, as described above. + .. versionchanged:: 3.11 Added support for marking individual keys as :data:`Required` or :data:`NotRequired`. See :pep:`655`.