Skip to content

Commit 0878b55

Browse files
committed
Reiterate on the code
1 parent e3538f5 commit 0878b55

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

Lib/functools.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,7 +1063,7 @@ def __init__(self, unbound, obj, cls):
10631063

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

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

10991098
if hasattr(method, "__get__"):
11001099
# If the method is a descriptor, it might be necessary
11011100
# to drop the first argument before calling
11021101
# as it can be no longer expected after descriptor access.
11031102
skip_bound_arg = False
11041103
if isinstance(method, staticmethod):
1105-
skip_bound_arg = self._skip_first_arg
1104+
skip_bound_arg = self._dispatch_arg_index == 1
11061105

11071106
method = method.__get__(self._obj, self._cls)
11081107
if isinstance(method, MethodType):
1109-
skip_bound_arg = self._skip_first_arg
1108+
skip_bound_arg = self._dispatch_arg_index == 1
11101109

11111110
if skip_bound_arg:
11121111
return method(*args[1:], **kwargs)

0 commit comments

Comments
 (0)