summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorRaymond Hettinger <rhettinger@users.noreply.github.com>2019-03-18 16:53:56 (GMT)
committerMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2019-03-18 16:53:56 (GMT)
commitf7b57df0c09c3a04ab27ba06eb2feb989bbb16cb (patch)
tree4c0a5cadcbb66984786e76ccb959c4b2a76c90a6 /Doc
parent1be0d1135f5627d0525eab635cf2da441d9cbc08 (diff)
downloadcpython-f7b57df0c09c3a04ab27ba06eb2feb989bbb16cb.zip
cpython-f7b57df0c09c3a04ab27ba06eb2feb989bbb16cb.tar.gz
cpython-f7b57df0c09c3a04ab27ba06eb2feb989bbb16cb.tar.bz2
bpo-36320: Switch typing.NamedTuple from OrderedDict to regular dict (GH-12396)
Also, deprecate the *_field_types* attributes which duplicated the information in *\__annotations__*. https://bugs.python.org/issue36320
Diffstat (limited to 'Doc')
-rw-r--r--Doc/library/typing.rst18
-rw-r--r--Doc/whatsnew/3.8.rst4
2 files changed, 18 insertions, 4 deletions
diff --git a/Doc/library/typing.rst b/Doc/library/typing.rst
index de03284..fad9dc6 100644
--- a/Doc/library/typing.rst
+++ b/Doc/library/typing.rst
@@ -838,10 +838,11 @@ The module defines the following classes, functions and decorators:
Fields with a default value must come after any fields without a default.
- The resulting class has two extra attributes: ``_field_types``,
- giving a dict mapping field names to types, and ``_field_defaults``, a dict
- mapping field names to default values. (The field names are in the
- ``_fields`` attribute, which is part of the namedtuple API.)
+ The resulting class has an extra attribute ``__annotations__`` giving a
+ dict that maps the field names to the field types. (The field names are in
+ the ``_fields`` attribute and the default values are in the
+ ``_field_defaults`` attribute both of which are part of the namedtuple
+ API.)
``NamedTuple`` subclasses can also have docstrings and methods::
@@ -863,6 +864,15 @@ The module defines the following classes, functions and decorators:
.. versionchanged:: 3.6.1
Added support for default values, methods, and docstrings.
+ .. versionchanged:: 3.8
+ Deprecated the ``_field_types`` attribute in favor of the more
+ standard ``__annotations__`` attribute which has the same information.
+
+ .. versionchanged:: 3.8
+ The ``_field_types`` and ``__annotations__`` attributes are
+ now regular dictionaries instead of instances of ``OrderedDict``.
+
+
.. function:: NewType(typ)
A helper function to indicate a distinct types to a typechecker,
diff --git a/Doc/whatsnew/3.8.rst b/Doc/whatsnew/3.8.rst
index 31baccd..2e311ab 100644
--- a/Doc/whatsnew/3.8.rst
+++ b/Doc/whatsnew/3.8.rst
@@ -510,6 +510,10 @@ Deprecated
(Contributed by Berker Peksag in :issue:`9372`.)
+* The :class:`typing.NamedTuple` class has deprecated the ``_field_types``
+ attribute in favor of the ``__annotations__`` attribute which has the same
+ information. (Contributed by Raymond Hettinger in :issue:`36320`.)
+
* :mod:`ast` classes ``Num``, ``Str``, ``Bytes``, ``NameConstant`` and
``Ellipsis`` are considered deprecated and will be removed in future Python
versions. :class:`~ast.Constant` should be used instead.