Skip to content

Commit 9c68543

Browse files
rhettingermiss-islington
authored andcommitted
Update the seealso entries for namedtuple() (GH-12373)
* 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.
1 parent 5927cfd commit 9c68543

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

Doc/library/collections.rst

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,17 +1028,20 @@ customize a prototype instance:
10281028

10291029
.. seealso::
10301030

1031-
* `Recipe for named tuple abstract base class with a metaclass mix-in
1032-
<https://code.activestate.com/recipes/577629-namedtupleabc-abstract-base-class-mix-in-for-named/>`_
1033-
by Jan Kaliszewski. Besides providing an :term:`abstract base class` for
1034-
named tuples, it also supports an alternate :term:`metaclass`-based
1035-
constructor that is convenient for use cases where named tuples are being
1036-
subclassed.
1031+
* See :class:`typing.NamedTuple` for a way to add type hints for named
1032+
tuples. It also provides an elegant notation using the :keyword:`class`
1033+
keyword::
1034+
1035+
class Component(NamedTuple):
1036+
part_number: int
1037+
weight: float
1038+
description: Optional[str] = None
10371039

10381040
* See :meth:`types.SimpleNamespace` for a mutable namespace based on an
10391041
underlying dictionary instead of a tuple.
10401042

1041-
* See :meth:`typing.NamedTuple` for a way to add type hints for named tuples.
1043+
* The :mod:`dataclasses` module provides a decorator and functions for
1044+
automatically adding generated special methods to user-defined classes.
10421045

10431046

10441047
:class:`OrderedDict` objects

Doc/library/typing.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -815,7 +815,7 @@ The module defines the following classes, functions and decorators:
815815

816816
.. class:: NamedTuple
817817

818-
Typed version of namedtuple.
818+
Typed version of :func:`collections.namedtuple`.
819819

820820
Usage::
821821

0 commit comments

Comments
 (0)