Skip to content

Commit a735d29

Browse files
committed
bpo-21767: explicitly mention abc support in functools.singledispatch docs
1 parent e8acc86 commit a735d29

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

Doc/library/functools.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,20 @@ The :mod:`functools` module defines the following functions:
423423
for the base ``object`` type, which means it is used if no better
424424
implementation is found.
425425

426+
If an implementation registered to :term:`abstract base class`, virtual
427+
subclasses will be dispatched to that implementation::
428+
429+
>>> from collections.abc import Mapping
430+
>>> @fun.register
431+
... def _(arg: Mapping, verbose=False):
432+
... if verbose:
433+
... print("Keys & Values")
434+
... for key, value in arg.items():
435+
... print(key, "=>", value)
436+
...
437+
>>> fun({"a": "b"})
438+
a => b
439+
426440
To check which implementation will the generic function choose for
427441
a given type, use the ``dispatch()`` attribute::
428442

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Explicitly mention abc support in functools.singledispatch

0 commit comments

Comments
 (0)