summaryrefslogtreecommitdiffstats
path: root/Doc/library
diff options
context:
space:
mode:
authorBatuhan Taşkaya <47358913+isidentical@users.noreply.github.com>2019-11-19 08:16:46 (GMT)
committerŁukasz Langa <lukasz@langa.pl>2019-11-19 08:16:46 (GMT)
commit24555ce2f969bd69517011d23aaf8cc481090211 (patch)
tree44acacebd530dd4b2b7ad726f571b3bbe421139c /Doc/library
parent9960230f76eb555d6dfbe8a324efed35610c85f9 (diff)
downloadcpython-24555ce2f969bd69517011d23aaf8cc481090211.zip
cpython-24555ce2f969bd69517011d23aaf8cc481090211.tar.gz
cpython-24555ce2f969bd69517011d23aaf8cc481090211.tar.bz2
bpo-21767: explicitly mention abc support in functools.singledispatch docs (#17171)
Diffstat (limited to 'Doc/library')
-rw-r--r--Doc/library/functools.rst14
1 files changed, 14 insertions, 0 deletions
diff --git a/Doc/library/functools.rst b/Doc/library/functools.rst
index cedc3ad..bb7aac4 100644
--- a/Doc/library/functools.rst
+++ b/Doc/library/functools.rst
@@ -423,6 +423,20 @@ The :mod:`functools` module defines the following functions:
for the base ``object`` type, which means it is used if no better
implementation is found.
+ If an implementation registered to :term:`abstract base class`, virtual
+ subclasses will be dispatched to that implementation::
+
+ >>> from collections.abc import Mapping
+ >>> @fun.register
+ ... def _(arg: Mapping, verbose=False):
+ ... if verbose:
+ ... print("Keys & Values")
+ ... for key, value in arg.items():
+ ... print(key, "=>", value)
+ ...
+ >>> fun({"a": "b"})
+ a => b
+
To check which implementation will the generic function choose for
a given type, use the ``dispatch()`` attribute::