diff options
Diffstat (limited to 'Doc/library/typing.rst')
-rw-r--r-- | Doc/library/typing.rst | 9 |
1 files changed, 9 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, |