[Python-checkins] cpython (3.6): Issue #28107: Update typing module documentation for NamedTuple (Ivan)

guido.van.rossum python-checkins at python.org
Tue Oct 25 12:54:31 EDT 2016


https://hg.python.org/cpython/rev/78c0487562d9
changeset: 104722:78c0487562d9
branch: 3.6
parent: 104720:ec12e16ea6a1
user: Guido van Rossum <guido at python.org>
date: Tue Oct 25 09:53:11 2016 -0700
summary:
 Issue #28107: Update typing module documentation for NamedTuple (Ivan)
files:
 Doc/library/typing.rst | 17 +++++++++++++----
 1 files changed, 13 insertions(+), 4 deletions(-)
diff --git a/Doc/library/typing.rst b/Doc/library/typing.rst
--- a/Doc/library/typing.rst
+++ b/Doc/library/typing.rst
@@ -677,23 +677,32 @@
 ``Pattern[str]``, ``Pattern[bytes]``, ``Match[str]``, or
 ``Match[bytes]``.
 
-.. function:: NamedTuple(typename, fields)
+.. class:: NamedTuple
 
 Typed version of namedtuple.
 
 Usage::
 
- Employee = typing.NamedTuple('Employee', [('name', str), ('id', int)])
+ class Employee(NamedTuple):
+ name: str
+ id: int
 
 This is equivalent to::
 
 Employee = collections.namedtuple('Employee', ['name', 'id'])
 
- The resulting class has one extra attribute: _field_types,
+ The resulting class has one extra attribute: ``_field_types``,
 giving a dict mapping field names to types. (The field names
- are in the _fields attribute, which is part of the namedtuple
+ are in the ``_fields`` attribute, which is part of the namedtuple
 API.)
 
+ Backward-compatible usage::
+
+ Employee = NamedTuple('Employee', [('name', str), ('id', int)])
+
+ .. versionchanged:: 3.6
+ Added support for :pep:`526` variable annotation syntax.
+
 .. function:: NewType(typ)
 
 A helper function to indicate a distinct types to a typechecker,
-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /