mirror of
https://github.com/python/cpython.git
synced 2025-10-01 21:02:15 +00:00
Improve glossary entry for ABCs.
- Rename reST target name for collections ABCs to avoid collisions - Link to glossary entry from numbers module doc (other modules already do it)
This commit is contained in:
parent
beb9170cc4
commit
8fde9506b7
4 changed files with 17 additions and 16 deletions
|
@ -27,12 +27,13 @@ Glossary
|
||||||
:ref:`2to3-reference`.
|
:ref:`2to3-reference`.
|
||||||
|
|
||||||
abstract base class
|
abstract base class
|
||||||
:ref:`abstract-base-classes` complement :term:`duck-typing` by
|
Abstract base classes complement :term:`duck-typing` by
|
||||||
providing a way to define interfaces when other techniques like
|
providing a way to define interfaces when other techniques like
|
||||||
:func:`hasattr` would be clumsy. Python comes with many built-in ABCs for
|
:func:`hasattr` would be clumsy or subtly wrong (for example with
|
||||||
|
:ref:`magic methods <new-style-special-lookup>`). Python comes with many built-in ABCs for
|
||||||
data structures (in the :mod:`collections` module), numbers (in the
|
data structures (in the :mod:`collections` module), numbers (in the
|
||||||
:mod:`numbers` module), and streams (in the :mod:`io` module). You can
|
:mod:`numbers` module), and streams (in the :mod:`io` module). You can
|
||||||
create your own ABC with the :mod:`abc` module.
|
create your own ABCs with the :mod:`abc` module.
|
||||||
|
|
||||||
argument
|
argument
|
||||||
A value passed to a function or method, assigned to a named local
|
A value passed to a function or method, assigned to a named local
|
||||||
|
@ -424,8 +425,8 @@ Glossary
|
||||||
mapping
|
mapping
|
||||||
A container object that supports arbitrary key lookups and implements the
|
A container object that supports arbitrary key lookups and implements the
|
||||||
methods specified in the :class:`Mapping` or :class:`MutableMapping`
|
methods specified in the :class:`Mapping` or :class:`MutableMapping`
|
||||||
:ref:`abstract base classes <abstract-base-classes>`. Examples include
|
:ref:`abstract base classes <collections-abstract-base-classes>`. Examples
|
||||||
:class:`dict`, :class:`collections.defaultdict`,
|
include :class:`dict`, :class:`collections.defaultdict`,
|
||||||
:class:`collections.OrderedDict` and :class:`collections.Counter`.
|
:class:`collections.OrderedDict` and :class:`collections.Counter`.
|
||||||
|
|
||||||
metaclass
|
metaclass
|
||||||
|
|
|
@ -9,8 +9,8 @@
|
||||||
|
|
||||||
.. versionadded:: 2.6
|
.. versionadded:: 2.6
|
||||||
|
|
||||||
This module provides the infrastructure for defining an :term:`abstract base
|
This module provides the infrastructure for defining :term:`abstract base
|
||||||
class` (ABCs) in Python, as outlined in :pep:`3119`; see the PEP for why this
|
classes <abstract base class>` (ABCs) in Python, as outlined in :pep:`3119`; see the PEP for why this
|
||||||
was added to Python. (See also :pep:`3141` and the :mod:`numbers` module
|
was added to Python. (See also :pep:`3141` and the :mod:`numbers` module
|
||||||
regarding a type hierarchy for numbers based on ABCs.)
|
regarding a type hierarchy for numbers based on ABCs.)
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ Python's general purpose built-in containers, :class:`dict`, :class:`list`,
|
||||||
===================== ==================================================================== ===========================
|
===================== ==================================================================== ===========================
|
||||||
|
|
||||||
In addition to the concrete container classes, the collections module provides
|
In addition to the concrete container classes, the collections module provides
|
||||||
:ref:`abstract-base-classes` that can be used to test whether a class provides a
|
:ref:`collections-abstract-base-classes` that can be used to test whether a class provides a
|
||||||
particular interface, for example, whether it is hashable or a mapping.
|
particular interface, for example, whether it is hashable or a mapping.
|
||||||
|
|
||||||
.. seealso::
|
.. seealso::
|
||||||
|
@ -851,8 +851,8 @@ If a new entry overwrites an existing entry, the
|
||||||
original insertion position is changed and moved to the end::
|
original insertion position is changed and moved to the end::
|
||||||
|
|
||||||
class LastUpdatedOrderedDict(OrderedDict):
|
class LastUpdatedOrderedDict(OrderedDict):
|
||||||
|
|
||||||
'Store items in the order the keys were last added'
|
'Store items in the order the keys were last added'
|
||||||
|
|
||||||
def __setitem__(self, key, value):
|
def __setitem__(self, key, value):
|
||||||
if key in self:
|
if key in self:
|
||||||
del self[key]
|
del self[key]
|
||||||
|
@ -871,10 +871,10 @@ so that the counter remembers the order elements are first encountered::
|
||||||
return self.__class__, (OrderedDict(self),)
|
return self.__class__, (OrderedDict(self),)
|
||||||
|
|
||||||
|
|
||||||
.. _abstract-base-classes:
|
.. _collections-abstract-base-classes:
|
||||||
|
|
||||||
ABCs - abstract base classes
|
Collections Abstract Base Classes
|
||||||
----------------------------
|
---------------------------------
|
||||||
|
|
||||||
The collections module offers the following :term:`ABCs <abstract base class>`:
|
The collections module offers the following :term:`ABCs <abstract base class>`:
|
||||||
|
|
||||||
|
@ -888,7 +888,7 @@ ABC Inherits from Abstract Methods Mixin
|
||||||
:class:`Sized` ``__len__``
|
:class:`Sized` ``__len__``
|
||||||
:class:`Callable` ``__call__``
|
:class:`Callable` ``__call__``
|
||||||
|
|
||||||
:class:`Sequence` :class:`Sized`, ``__getitem__`` ``__contains__``. ``__iter__``, ``__reversed__``,
|
:class:`Sequence` :class:`Sized`, ``__getitem__`` ``__contains__``, ``__iter__``, ``__reversed__``,
|
||||||
:class:`Iterable`, ``index``, and ``count``
|
:class:`Iterable`, ``index``, and ``count``
|
||||||
:class:`Container`
|
:class:`Container`
|
||||||
|
|
||||||
|
|
|
@ -7,9 +7,9 @@
|
||||||
.. versionadded:: 2.6
|
.. versionadded:: 2.6
|
||||||
|
|
||||||
|
|
||||||
The :mod:`numbers` module (:pep:`3141`) defines a hierarchy of numeric abstract
|
The :mod:`numbers` module (:pep:`3141`) defines a hierarchy of numeric
|
||||||
base classes which progressively define more operations. None of the types
|
:term:`abstract base classes <abstract base class>` which progressively define
|
||||||
defined in this module can be instantiated.
|
more operations. None of the types defined in this module can be instantiated.
|
||||||
|
|
||||||
|
|
||||||
.. class:: Number
|
.. class:: Number
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue