]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Update the seealso entries for namedtuple() (GH-12373)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Sat, 16 Mar 2019 20:01:35 +0000 (13:01 -0700)
committerGitHub <noreply@github.com>
Sat, 16 Mar 2019 20:01:35 +0000 (13:01 -0700)
* Replace external recipe link with a link to the dataclasses module.

* Highlight the class definition syntax for typing.NamedTuple
  and add an example for clarity.
(cherry picked from commit 9c68543f022b130ff51944edc6771c60510ee683)

Co-authored-by: Raymond Hettinger <rhettinger@users.noreply.github.com>
Doc/library/collections.rst
Doc/library/typing.rst

index 0413f469228a4beb8a556342e3637f830ee5d5d1..febaa4bf4620c2b50bf6c18e94ff11f0956d7eb3 100644 (file)
@@ -1016,17 +1016,20 @@ customize a prototype instance:
 
 .. seealso::
 
-    * `Recipe for named tuple abstract base class with a metaclass mix-in
-      <https://code.activestate.com/recipes/577629-namedtupleabc-abstract-base-class-mix-in-for-named/>`_
-      by Jan Kaliszewski.  Besides providing an :term:`abstract base class` for
-      named tuples, it also supports an alternate :term:`metaclass`-based
-      constructor that is convenient for use cases where named tuples are being
-      subclassed.
+    * See :class:`typing.NamedTuple` for a way to add type hints for named
+      tuples.  It also provides an elegant notation using the :keyword:`class`
+      keyword::
+
+          class Component(NamedTuple):
+              part_number: int
+              weight: float
+              description: Optional[str] = None
 
     * 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.
+    * The :mod:`dataclasses` module provides a decorator and functions for
+      automatically adding generated special methods to user-defined classes.
 
 
 :class:`OrderedDict` objects
index e756062240c9297f0b3ea6eba2d978259426ac7d..6f1c85feb0eb0d375abc97d7d8837d859c43e389 100644 (file)
@@ -815,7 +815,7 @@ The module defines the following classes, functions and decorators:
 
 .. class:: NamedTuple
 
-   Typed version of namedtuple.
+   Typed version of :func:`collections.namedtuple`.
 
    Usage::