Skip to content

Commit ebdb68d

Browse files
committed
Raise exception if positional argument not found
1 parent 69b9978 commit ebdb68d

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

Lib/functools.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -895,7 +895,13 @@ def _get_dispatch_param_name(func, *, skip_first_param=False):
895895
func_code = func.__code__
896896
pos_param_count = func_code.co_argcount
897897
params = func_code.co_varnames
898-
return next(iter(params[skip_first_param:pos_param_count]), None)
898+
try:
899+
return params[skip_first_param:pos_param_count][0]
900+
except IndexError:
901+
raise TypeError(
902+
f"Invalid first argument to `register()`: function {func!r}"
903+
f"does not accept positional arguments."
904+
)
899905

900906
def _get_dispatch_annotation(func, param):
901907
import annotationlib, typing
@@ -905,7 +911,7 @@ def _get_dispatch_annotation(func, param):
905911
except KeyError:
906912
raise TypeError(
907913
f"Invalid first argument to `register()`: {param!r}. "
908-
f"Add missing annotation to parameter {param!r} of {func.__qualname__!r} "
914+
f"Add missing annotation to parameter {param!r} of {func!r} "
909915
f"or use `@register(some_class)`."
910916
) from None
911917
return fwdref_or_typeform

0 commit comments

Comments
 (0)