Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Doc/library/functools.rst
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,12 @@ The :mod:`functools` module defines the following functions:
The same pattern can be used for other similar decorators:
:deco:`staticmethod`, :deco:`~abc.abstractmethod`, and others.

``singledispatchmethod`` always dispatches on the first argument passed at call
time, irrespective of whether the method is bound or unbound. As a result,
calling the method through an instance or through the class may result in
different dispatch behavior. This behavior is required to support correct
dispatch when used with ``staticmethod`` and ``classmethod``.

Comment on lines +721 to +726
Copy link
Member

@johnslavik johnslavik Jan 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not clear what "the method" in the first sentence refers to.

As a result, calling the method through an instance or through the class may result in different dispatch behavior.

Exact opposite: it's the same dispatch behavior, but a potentially surprising dispatch result.

This behavior is required to support correct dispatch when used with staticmethod and classmethod.

I assume this is a detail that's not necessary for the reader who's just figuring out singledispatchmethod.
Let's not include it.

My suggestion (click "Commit suggestion" to apply it directly):

Suggested change
``singledispatchmethod`` always dispatches on the first argument passed at call
time, irrespective of whether the method is bound or unbound. As a result,
calling the method through an instance or through the class may result in
different dispatch behavior. This behavior is required to support correct
dispatch when used with ``staticmethod`` and ``classmethod``.
For every ``singledispatchmethod`` method defined in a class, the value
dispatched on by that method is *always* the first argument passed for the call.
Therefore, dispatching to regular methods can only be sensibly performed by
calling such a method from instances of the class, and not from the class object.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@picnixz, do you like this wording? Do you have a better idea?

.. versionadded:: 3.8

.. versionchanged:: 3.15
Expand Down
Loading