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

Skip to content
Merged
Show file tree
Hide file tree
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
Fix staticmethod bug
  • Loading branch information
johnslavik committed Feb 15, 2026
commit 85c318dcfe1c77fd92e6a162f8fe508e5ca0e871
13 changes: 12 additions & 1 deletion Lib/functools.py
Original file line number Diff line number Diff line change
Expand Up @@ -1100,9 +1100,20 @@ def __call__(self, /, *args, **kwargs):
method = self._dispatch(args[1].__class__)
else:
method = self._dispatch(args[0].__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_first_arg = False
if isinstance(method, staticmethod):
skip_first_arg = self._skip_bound_arg

method = method.__get__(self._obj, self._cls)
if self._skip_bound_arg and isinstance(method, MethodType):
if isinstance(method, MethodType):
skip_first_arg = self._skip_bound_arg

if skip_first_arg:
return method(*args[1:], **kwargs)
return method(*args, **kwargs)

Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_functools.py
Original file line number Diff line number Diff line change
Expand Up @@ -3023,7 +3023,7 @@ def special2(self, x: float):

@generic.register
@staticmethod
def special3(self, x: complex):
def special3(x: complex):
return "special3"

def special4(self, x):
Expand Down
Loading