mirror of
https://github.com/python/cpython.git
synced 2025-11-27 13:45:25 +00:00
moved the single-dispatch generic function definitions to the glossary
This commit is contained in:
parent
7f7a67aac8
commit
fdcf2b7d4e
2 changed files with 15 additions and 6 deletions
|
|
@ -302,6 +302,15 @@ Glossary
|
||||||
>>> sum(i*i for i in range(10)) # sum of squares 0, 1, 4, ... 81
|
>>> sum(i*i for i in range(10)) # sum of squares 0, 1, 4, ... 81
|
||||||
285
|
285
|
||||||
|
|
||||||
|
generic function
|
||||||
|
A function composed of multiple functions implementing the same operation
|
||||||
|
for different types. Which implementation should be used during a call is
|
||||||
|
determined by the dispatch algorithm.
|
||||||
|
|
||||||
|
See also the :term:`single dispatch` glossary entry, the
|
||||||
|
:func:`functools.singledispatch` decorator, and :pep:`443`.
|
||||||
|
|
||||||
|
|
||||||
GIL
|
GIL
|
||||||
See :term:`global interpreter lock`.
|
See :term:`global interpreter lock`.
|
||||||
|
|
||||||
|
|
@ -745,6 +754,10 @@ Glossary
|
||||||
mapping rather than a sequence because the lookups use arbitrary
|
mapping rather than a sequence because the lookups use arbitrary
|
||||||
:term:`immutable` keys rather than integers.
|
:term:`immutable` keys rather than integers.
|
||||||
|
|
||||||
|
single dispatch
|
||||||
|
A form of :term:`generic function` dispatch where the implementation is
|
||||||
|
chosen based on the type of a single argument.
|
||||||
|
|
||||||
slice
|
slice
|
||||||
An object usually containing a portion of a :term:`sequence`. A slice is
|
An object usually containing a portion of a :term:`sequence`. A slice is
|
||||||
created using the subscript notation, ``[]`` with colons between numbers
|
created using the subscript notation, ``[]`` with colons between numbers
|
||||||
|
|
|
||||||
|
|
@ -189,12 +189,8 @@ The :mod:`functools` module defines the following functions:
|
||||||
|
|
||||||
.. decorator:: singledispatch(default)
|
.. decorator:: singledispatch(default)
|
||||||
|
|
||||||
Transforms a function into a single-dispatch generic function. A **generic
|
Transforms a function into a :term:`single-dispatch <single
|
||||||
function** is composed of multiple functions implementing the same operation
|
dispatch>` :term:`generic function`.
|
||||||
for different types. Which implementation should be used during a call is
|
|
||||||
determined by the dispatch algorithm. When the implementation is chosen
|
|
||||||
based on the type of a single argument, this is known as **single
|
|
||||||
dispatch**.
|
|
||||||
|
|
||||||
To define a generic function, decorate it with the ``@singledispatch``
|
To define a generic function, decorate it with the ``@singledispatch``
|
||||||
decorator. Note that the dispatch happens on the type of the first argument,
|
decorator. Note that the dispatch happens on the type of the first argument,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue