Skip to content

Commit 7fcf4d5

Browse files
committed
Rename the ugly _inside_dispatchmethod to __role__
1 parent fc5df46 commit 7fcf4d5

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

Lib/functools.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -888,7 +888,7 @@ def _find_impl(cls, registry):
888888
match = t
889889
return registry.get(match)
890890

891-
def _get_singledispatch_annotated_param(func, *, _inside_dispatchmethod=False):
891+
def _get_singledispatch_annotated_param(func, *, __role__):
892892
"""Find the first positional and user-specified parameter in a callable
893893
or descriptor.
894894
@@ -906,7 +906,7 @@ def _get_singledispatch_annotated_param(func, *, _inside_dispatchmethod=False):
906906
# Pick the first parameter if registering via singledispatch.
907907
# Pick the second parameter if registering via singledispatchmethod.
908908
else:
909-
idx = int(_inside_dispatchmethod)
909+
idx = 0 if __role__ == "function" else 1
910910

911911
# If it is a simple function, try to read from the code object fast.
912912
if isinstance(func, FunctionType) and not hasattr(func, "__wrapped__"):
@@ -981,7 +981,7 @@ def _is_valid_dispatch_type(cls):
981981
return (isinstance(cls, UnionType) and
982982
all(isinstance(arg, type) for arg in cls.__args__))
983983

984-
def register(cls, func=None, _inside_dispatchmethod=False):
984+
def register(cls, func=None, __role__="function"):
985985
"""generic_func.register(cls, func) -> func
986986
987987
Registers a new implementation for the given *cls* on a *generic_func*.
@@ -1006,8 +1006,7 @@ def register(cls, func=None, _inside_dispatchmethod=False):
10061006
)
10071007
func = cls
10081008

1009-
argname = _get_singledispatch_annotated_param(
1010-
func, _inside_dispatchmethod=_inside_dispatchmethod)
1009+
argname = _get_singledispatch_annotated_param(func, __role__=__role__)
10111010

10121011
# only import typing if annotation parsing is necessary
10131012
from typing import get_type_hints
@@ -1086,7 +1085,7 @@ def register(self, cls, method=None):
10861085
10871086
Registers a new implementation for the given *cls* on a *generic_method*.
10881087
"""
1089-
return self.dispatcher.register(cls, func=method, _inside_dispatchmethod=True)
1088+
return self.dispatcher.register(cls, func=method, __role__="method")
10901089

10911090
def __get__(self, obj, cls=None):
10921091
return _singledispatchmethod_get(self, obj, cls)

0 commit comments

Comments
 (0)