Skip to content

Commit 0a622fb

Browse files
committed
Bring back comments but make them actually helpful
1 parent cd10e91 commit 0a622fb

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

Lib/functools.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -895,21 +895,22 @@ def _get_singledispatch_annotated_param(func, *, __role__):
895895
Used by singledispatch for registration by type annotation of the parameter.
896896
"""
897897
if isinstance(func, staticmethod):
898-
idx = 0
898+
idx = 0 # Nothing to skip.
899899
func = func.__func__
900900
elif isinstance(func, (classmethod, MethodType)):
901-
idx = 1
901+
idx = 1 # Skip 'cls' or 'self'.
902902
func = func.__func__
903903
else:
904+
# Skip 'self' when called from `@singledispatchmethod.register`.
904905
idx = 0 if __role__ == "function" else 1
905-
# Fast path: emulate inspect._signature_from_function if possible.
906+
# Fast path: emulate `inspect._signature_from_function` if possible.
906907
if isinstance(func, FunctionType) and not hasattr(func, "__wrapped__"):
907908
func_code = func.__code__
908909
try:
909910
return func_code.co_varnames[:func_code.co_argcount][idx]
910911
except IndexError:
911912
pass
912-
# Fall back to inspect.signature (slower, but complete).
913+
# Fall back to `inspect.signature` (slower, but complete).
913914
import inspect
914915
params = list(inspect.signature(func).parameters.values())
915916
try:

0 commit comments

Comments
 (0)