diff options
author | Raymond Hettinger <rhettinger@users.noreply.github.com> | 2019-03-16 19:53:23 (GMT) |
---|---|---|
committer | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2019-03-16 19:53:23 (GMT) |
commit | 9c68543f022b130ff51944edc6771c60510ee683 (patch) | |
tree | 50807bcfdc28d395377346a4139670b07609df92 | |
parent | 5927cfdf3a657384dd7632938759a3ac096db7e3 (diff) | |
download | cpython-9c68543f022b130ff51944edc6771c60510ee683.zip cpython-9c68543f022b130ff51944edc6771c60510ee683.tar.gz cpython-9c68543f022b130ff51944edc6771c60510ee683.tar.bz2 |
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.
-rw-r--r-- | Doc/library/collections.rst | 17 | ||||
-rw-r--r-- | Doc/library/typing.rst | 2 |
2 files changed, 11 insertions, 8 deletions
diff --git a/Doc/library/collections.rst b/Doc/library/collections.rst index 5c783d4..daa7414 100644 --- a/Doc/library/collections.rst +++ b/Doc/library/collections.rst @@ -1028,17 +1028,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 diff --git a/Doc/library/typing.rst b/Doc/library/typing.rst index 6ed09f1..de03284 100644 --- a/Doc/library/typing.rst +++ b/Doc/library/typing.rst @@ -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:: |