Skip to content

Commit e238e6a

Browse files
committed
Use a match statement instead of a for loop
1 parent c406755 commit e238e6a

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
@@ -895,7 +895,7 @@ def _get_dispatch_param(func, *, _dispatchmethod=False):
895895
Used by singledispatch for registration by type annotation of the parameter.
896896
"""
897897
# Fast path for typical callables and descriptors.
898-
# 0 from singledispatch(), 1 from singledispatchmethod()
898+
# idx is 0 when singledispatch() and 1 when singledispatchmethod()
899899
idx = _dispatchmethod
900900
if isinstance(func, staticmethod):
901901
idx = 0
@@ -910,10 +910,9 @@ def _get_dispatch_param(func, *, _dispatchmethod=False):
910910
pass
911911
# Fallback path for more nuanced inspection of ambiguous callables.
912912
import inspect
913-
for param in list(inspect.signature(func).parameters.values())[idx:]:
914-
if param.kind in (param.KEYWORD_ONLY, param.VAR_KEYWORD):
915-
break
916-
return param.name
913+
match list(inspect.signature(func).parameters.values())[idx:]:
914+
case [param] if param.kind < 3: # (*, param) or (**param)
915+
return param.name
917916
return None
918917

919918
def singledispatch(func):

0 commit comments

Comments
 (0)