]> granicus.if.org Git - python/commitdiff
Issue #28107: Update typing module documentation for NamedTuple (Ivan)
authorGuido van Rossum <guido@python.org>
Tue, 25 Oct 2016 16:53:11 +0000 (09:53 -0700)
committerGuido van Rossum <guido@python.org>
Tue, 25 Oct 2016 16:53:11 +0000 (09:53 -0700)
Doc/library/typing.rst

index bbf5db6891bc4668b959a539a286e986679021a8..a0666fed39acc1bd069f026084c0883bece3f5a5 100644 (file)
@@ -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,