Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
5ec24314
Commit
5ec24314
authored
Oct 25, 2016
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #28107: Update typing module documentation for NamedTuple (Ivan)
parent
28f98206
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
4 deletions
+13
-4
Doc/library/typing.rst
Doc/library/typing.rst
+13
-4
No files found.
Doc/library/typing.rst
View file @
5ec24314
...
...
@@ -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,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment