Skip to content

Commit 052c2fd

Browse files
committed
Better comments
1 parent 50c0e64 commit 052c2fd

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

Lib/functools.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -894,22 +894,21 @@ def _get_dispatch_param(func, *, _inside_dispatchmethod=False):
894894
895895
Used by singledispatch for registration by type annotation of the parameter.
896896
"""
897-
# Fast path for typical callables and descriptors.
898-
899-
# For staticmethods always pick the first parameter.
897+
# Pick the first parameter if function had @staticmethod.
900898
if isinstance(func, staticmethod):
901899
idx = 0
902900
func = func.__func__
903-
# For classmethods and bound methods always pick the second parameter.
901+
# Pick the second parameter if function had @classmethod or is any bound method.
904902
elif isinstance(func, (classmethod, MethodType)):
905903
idx = 1
906904
func = func.__func__
907-
# For unbound methods and functions, pick:
908-
# - the first parameter if calling from singledispatch()
909-
# - the second parameter if calling from singledispatchmethod()
905+
# If it is likely a regular function:
906+
# Pick the first parameter if calling from singledispatch().
907+
# Pick the second parameter if calling from singledispatchmethod.
910908
else:
911909
idx = _inside_dispatchmethod
912910

911+
# If it is a simple function, try to fast read from the code object.
913912
if isinstance(func, FunctionType) and not hasattr(func, "__wrapped__"):
914913
# Emulate inspect._signature_from_function to get the desired parameter.
915914
func_code = func.__code__
@@ -918,7 +917,7 @@ def _get_dispatch_param(func, *, _inside_dispatchmethod=False):
918917
except IndexError:
919918
pass
920919

921-
# Fallback path for more nuanced inspection of ambiguous callables.
920+
# Otherwise delegate wrapped or ambiguous callables to inspect.signature (slower).
922921
import inspect
923922
try:
924923
param = list(inspect.signature(func).parameters.values())[idx]

0 commit comments

Comments
 (0)