Skip to content

Commit 2834c45

Browse files
gh-143535: Clarify dispatch semantics of singledispatchmethod
1 parent 119a4b1 commit 2834c45

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

Doc/library/functools.rst

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -692,11 +692,6 @@ The :mod:`functools` module defines the following functions:
692692
@neg.register
693693
def _(self, arg: bool):
694694
return not arg
695-
.. note::
696-
``singledispatchmethod`` dispatches the first argument during call
697-
time irrespective of whether the method is bound or unbound, as a result,
698-
``x.f(a) != C.f(x, a)``.The behavior is intentional and required to support correct dispatch for
699-
``staticmethod`` and ``classmethod``.
700695

701696
``@singledispatchmethod`` supports nesting with other decorators such as
702697
:deco:`classmethod`. Note that to allow for
@@ -723,6 +718,12 @@ The :mod:`functools` module defines the following functions:
723718
The same pattern can be used for other similar decorators:
724719
:deco:`staticmethod`, :deco:`~abc.abstractmethod`, and others.
725720

721+
``singledispatchmethod`` always dispatches on the first argument passed at call
722+
time, irrespective of whether the method is bound or unbound. As a result,
723+
calling the method through an instance or through the class may result in
724+
different dispatch behavior. This behavior is required to support correct
725+
dispatch when used with ``staticmethod`` and ``classmethod``.
726+
726727
.. versionadded:: 3.8
727728

728729
.. versionchanged:: 3.15

0 commit comments

Comments
 (0)