Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Reiterate on the code
  • Loading branch information
johnslavik committed Feb 16, 2026
commit 0878b550a716e9b4c1ddf500304d666bf4c2d4af
9 changes: 4 additions & 5 deletions Lib/functools.py
Original file line number Diff line number Diff line change
Expand Up @@ -1063,7 +1063,7 @@ def __init__(self, unbound, obj, cls):

# Dispatch on the second argument if a generic method turns into
# a bound method on instance-level access. See GH-143535.
self._skip_first_arg = obj is None and isinstance(func, FunctionType)
self._dispatch_arg_index = 1 if obj is None and isinstance(func, FunctionType) else 0

try:
self.__module__ = func.__module__
Expand Down Expand Up @@ -1093,20 +1093,19 @@ def __call__(self, /, *args, **kwargs):
'singledispatchmethod method')
raise TypeError(f'{funcname} requires at least '
'1 positional argument')
index = 1 if self._skip_first_arg else 0
method = self._dispatch(args[index].__class__)
method = self._dispatch(args[self._dispatch_arg_index].__class__)

if hasattr(method, "__get__"):
# If the method is a descriptor, it might be necessary
# to drop the first argument before calling
# as it can be no longer expected after descriptor access.
skip_bound_arg = False
if isinstance(method, staticmethod):
skip_bound_arg = self._skip_first_arg
skip_bound_arg = self._dispatch_arg_index == 1

method = method.__get__(self._obj, self._cls)
if isinstance(method, MethodType):
skip_bound_arg = self._skip_first_arg
skip_bound_arg = self._dispatch_arg_index == 1

if skip_bound_arg:
return method(*args[1:], **kwargs)
Expand Down
Loading