summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
Diffstat (limited to 'Doc')
-rw-r--r--Doc/library/typing.rst9
-rw-r--r--Doc/whatsnew/3.11.rst4
2 files changed, 13 insertions, 0 deletions
diff --git a/Doc/library/typing.rst b/Doc/library/typing.rst
index 868ea1b..05ac057 100644
--- a/Doc/library/typing.rst
+++ b/Doc/library/typing.rst
@@ -1615,6 +1615,12 @@ These are not used in annotations. They are building blocks for declaring types.
def __repr__(self) -> str:
return f'<Employee {self.name}, id={self.id}>'
+ ``NamedTuple`` subclasses can be generic::
+
+ class Group(NamedTuple, Generic[T]):
+ key: T
+ group: list[T]
+
Backward-compatible usage::
Employee = NamedTuple('Employee', [('name', str), ('id', int)])
@@ -1633,6 +1639,9 @@ These are not used in annotations. They are building blocks for declaring types.
Removed the ``_field_types`` attribute in favor of the more
standard ``__annotations__`` attribute which has the same information.
+ .. versionchanged:: 3.11
+ Added support for generic namedtuples.
+
.. class:: NewType(name, tp)
A helper class to indicate a distinct type to a typechecker,
diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst
index 0a8ba1e..80ce462 100644
--- a/Doc/whatsnew/3.11.rst
+++ b/Doc/whatsnew/3.11.rst
@@ -715,6 +715,10 @@ For major changes, see :ref:`new-feat-related-type-hints-311`.
to clear all registered overloads of a function.
(Contributed by Jelle Zijlstra in :gh:`89263`.)
+* :class:`~typing.NamedTuple` subclasses can be generic.
+ (Contributed by Serhiy Storchaka in :issue:`43923`.)
+
+
unicodedata
-----------