summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2016-10-25 16:54:11 (GMT)
committerGuido van Rossum <guido@python.org>2016-10-25 16:54:11 (GMT)
commit398134d50cb2b905d6ca28f2bceae755a39ab315 (patch)
tree4ca5b9185f359f49417a14430c7bb4e30fde3524
parent11e9a1654842874928f01ceb2bf4e9881675b618 (diff)
parent5ec24314cd4a8b8c649d57fddad20d2a53fef1d5 (diff)
downloadcpython-398134d50cb2b905d6ca28f2bceae755a39ab315.zip
cpython-398134d50cb2b905d6ca28f2bceae755a39ab315.tar.gz
cpython-398134d50cb2b905d6ca28f2bceae755a39ab315.tar.bz2
Issue #28107: Update typing module documentation for NamedTuple (Ivan) (3.6->3.7)
-rw-r--r--Doc/library/typing.rst17
1 files changed, 13 insertions, 4 deletions
diff --git a/Doc/library/typing.rst b/Doc/library/typing.rst
index bbf5db6..a0666fe 100644
--- a/Doc/library/typing.rst
+++ b/Doc/library/typing.rst
@@ -677,23 +677,32 @@ The module defines the following classes, functions and decorators:
``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,