[Python-checkins] cpython: Add cross-reference to typing.NamedTuple. Doctest two more examples.
raymond.hettinger
python-checkins at python.org
Tue Aug 16 16:13:21 EDT 2016
https://hg.python.org/cpython/rev/e7682f193c96
changeset: 102708:e7682f193c96
user: Raymond Hettinger <python at rcn.com>
date: Tue Aug 16 13:13:17 2016 -0700
summary:
Add cross-reference to typing.NamedTuple. Doctest two more examples.
files:
Doc/library/collections.rst | 14 ++++++++++----
1 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/Doc/library/collections.rst b/Doc/library/collections.rst
--- a/Doc/library/collections.rst
+++ b/Doc/library/collections.rst
@@ -850,7 +850,9 @@
.. method:: somenamedtuple._asdict()
Return a new :class:`OrderedDict` which maps field names to their corresponding
- values::
+ values:
+
+ .. doctest::
>>> p = Point(x=11, y=22)
>>> p._asdict()
@@ -912,7 +914,9 @@
functionality with a subclass. Here is how to add a calculated field and
a fixed-width print format:
- >>> class Point(namedtuple('Point', 'x y')):
+.. doctest::
+
+ >>> class Point(namedtuple('Point', ['x', 'y'])):
... __slots__ = ()
... @property
... def hypot(self):
@@ -963,8 +967,10 @@
constructor that is convenient for use cases where named tuples are being
subclassed.
- * :meth:`types.SimpleNamespace` for a mutable namespace based on an underlying
- dictionary instead of a tuple.
+ * See :meth:`types.SimpleNamespace` for a mutable namespace based on an
+ underlying dictionary instead of a tuple.
+
+ * See :meth:`typing.NamedTuple` for a way to add type hints for named tuples.
:class:`OrderedDict` objects
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list