Skip to content

Commit fc5df46

Browse files
johnslavikjaraco
andcommitted
Raise in _get_singledispatch_annotated_param
Co-authored-by: Jason R. Coombs <jaraco@jaraco.com>
1 parent 48d1bde commit fc5df46

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
@@ -928,7 +928,11 @@ def _get_singledispatch_annotated_param(func, *, _inside_dispatchmethod=False):
928928
# Allow variadic positional "(*args)" parameters for backward compatibility.
929929
if param.kind not in (inspect.Parameter.KEYWORD_ONLY, inspect.Parameter.VAR_KEYWORD):
930930
return param.name
931-
return None
931+
932+
raise TypeError(
933+
f"Invalid first argument to `register()`: {func!r} "
934+
f"does not accept positional arguments."
935+
)
932936

933937
def singledispatch(func):
934938
"""Single-dispatch generic function decorator.
@@ -1004,11 +1008,6 @@ def register(cls, func=None, _inside_dispatchmethod=False):
10041008

10051009
argname = _get_singledispatch_annotated_param(
10061010
func, _inside_dispatchmethod=_inside_dispatchmethod)
1007-
if argname is None:
1008-
raise TypeError(
1009-
f"Invalid first argument to `register()`: {func!r} "
1010-
f"does not accept positional arguments."
1011-
)
10121011

10131012
# only import typing if annotation parsing is necessary
10141013
from typing import get_type_hints

0 commit comments

Comments
 (0)