From 24555ce2f969bd69517011d23aaf8cc481090211 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Batuhan=20Ta=C5=9Fkaya?= <47358913+isidentical@users.noreply.github.com> Date: Tue, 19 Nov 2019 11:16:46 +0300 Subject: bpo-21767: explicitly mention abc support in functools.singledispatch docs (#17171) --- Doc/library/functools.rst | 14 ++++++++++++++ .../Documentation/2019-11-17-11-54-57.bpo-21767.Qq3Dos.rst | 1 + 2 files changed, 15 insertions(+) create mode 100644 Misc/NEWS.d/next/Documentation/2019-11-17-11-54-57.bpo-21767.Qq3Dos.rst 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:: diff --git a/Misc/NEWS.d/next/Documentation/2019-11-17-11-54-57.bpo-21767.Qq3Dos.rst b/Misc/NEWS.d/next/Documentation/2019-11-17-11-54-57.bpo-21767.Qq3Dos.rst new file mode 100644 index 0000000..1e2a45e --- /dev/null +++ b/Misc/NEWS.d/next/Documentation/2019-11-17-11-54-57.bpo-21767.Qq3Dos.rst @@ -0,0 +1 @@ +Explicitly mention abc support in functools.singledispatch -- cgit v0.12