Message407579
Maybe something like this:
diff --git a/Doc/library/typing.rst b/Doc/library/typing.rst
index 735d477db4..8de913d8db 100644
--- a/Doc/library/typing.rst
+++ b/Doc/library/typing.rst
@@ -1291,7 +1291,8 @@ These are not used in annotations. They are building blocks for declaring types.
.. class:: NamedTuple
- Typed version of :func:`collections.namedtuple`.
+ Typed version of :func:`collections.namedtuple`, annotated fields are passed
+ to an underlying `collections.namedtuple`.
Usage::
@@ -1311,9 +1312,20 @@ These are not used in annotations. They are building blocks for declaring types.
employee = Employee('Guido')
assert employee.id == 3
+ assert employee == ('Guido', 3)
Fields with a default value must come after any fields without a default.
+ Non-annotated fields will not be part of the `collections.namedtuple`::
+
+ class Employee(NamedTuple):
+ name = 'Guido'
+ id = 3
+
+ employee = Employee()
+ assert employee.id == 3
+ assert not employee # Passes because the collections.namedtuple is empty
+
The resulting class has an extra attribute ``__annotations__`` giving a
dict that maps the field names to the field types. (The field names are in |
|
Date |
User |
Action |
Args |
2021-12-03 11:44:35 | emontnemery | set | recipients:
+ emontnemery, gvanrossum, eric.smith, Spencer Brown, kj, AlexWaygood |
2021-12-03 11:44:35 | emontnemery | set | messageid: <1638531875.32.0.4151754765.issue45972@roundup.psfhosted.org> |
2021-12-03 11:44:35 | emontnemery | link | issue45972 messages |
2021-12-03 11:44:35 | emontnemery | create | |
|