Skip to content

Commit 85c318d

Browse files
committed
Fix staticmethod bug
1 parent dd804d2 commit 85c318d

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

Lib/functools.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1100,9 +1100,20 @@ def __call__(self, /, *args, **kwargs):
11001100
method = self._dispatch(args[1].__class__)
11011101
else:
11021102
method = self._dispatch(args[0].__class__)
1103+
11031104
if hasattr(method, "__get__"):
1105+
# If the method is a descriptor, it might be necessary
1106+
# to drop the first argument before calling
1107+
# as it can be no longer expected after descriptor access.
1108+
skip_first_arg = False
1109+
if isinstance(method, staticmethod):
1110+
skip_first_arg = self._skip_bound_arg
1111+
11041112
method = method.__get__(self._obj, self._cls)
1105-
if self._skip_bound_arg and isinstance(method, MethodType):
1113+
if isinstance(method, MethodType):
1114+
skip_first_arg = self._skip_bound_arg
1115+
1116+
if skip_first_arg:
11061117
return method(*args[1:], **kwargs)
11071118
return method(*args, **kwargs)
11081119

Lib/test/test_functools.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3023,7 +3023,7 @@ def special2(self, x: float):
30233023

30243024
@generic.register
30253025
@staticmethod
3026-
def special3(self, x: complex):
3026+
def special3(x: complex):
30273027
return "special3"
30283028

30293029
def special4(self, x):

0 commit comments

Comments
 (0)