cpython: 78c0487562d9 (original) (raw)
Mercurial > cpython
changeset 104722:78c0487562d9 3.6
Issue #28107: Update typing module documentation for NamedTuple (Ivan) [#28107]
Guido van Rossum guido@python.org | |
---|---|
date | Tue, 25 Oct 2016 09:53:11 -0700 |
parents | ec12e16ea6a1 |
children | 709b19b9d6ea 84a3c5003510 |
files | Doc/library/typing.rst |
diffstat | 1 files changed, 13 insertions(+), 4 deletions(-)[+] [-] Doc/library/typing.rst 17 |
line wrap: on
line diff
--- a/Doc/library/typing.rst
+++ b/Doc/library/typing.rst
@@ -677,23 +677,32 @@ The module defines the following classes
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)])[](#l1.14)
class Employee(NamedTuple):[](#l1.15)
name: str[](#l1.16)
id: int[](#l1.17)
This is equivalent to:: Employee = collections.namedtuple('Employee', ['name', 'id'])
- 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 API.) - Backward-compatible usage:: +
Employee = NamedTuple('Employee', [('name', str), ('id', int)])[](#l1.32)
+ .. function:: NewType(typ) A helper function to indicate a distinct types to a typechecker,