File tree Expand file tree Collapse file tree 2 files changed +10
-6
lines changed Expand file tree Collapse file tree 2 files changed +10
-6
lines changed Original file line number Diff line number Diff line change @@ -848,9 +848,11 @@ def register(cls, func=None):
848
848
# only import typing if annotation parsing is necessary
849
849
from typing import get_type_hints
850
850
argname , cls = next (iter (get_type_hints (func ).items ()))
851
- assert isinstance (cls , type ), (
852
- f"Invalid annotation for { argname !r} . { cls !r} is not a class."
853
- )
851
+ if not isinstance (cls , type ):
852
+ raise TypeError (
853
+ f"Invalid annotation for { argname !r} . "
854
+ f"{ cls !r} is not a class."
855
+ )
854
856
registry [cls ] = func
855
857
if cache_token is None and hasattr (cls , '__abstractmethods__' ):
856
858
cache_token = get_cache_token ()
Original file line number Diff line number Diff line change @@ -2304,10 +2304,12 @@ def _(arg: typing.Iterable[str]):
2304
2304
# types from `typing`. Instead, annotate with regular types
2305
2305
# or ABCs.
2306
2306
return "I annotated with a generic collection"
2307
- self .assertTrue (str (exc .exception ).startswith (msg_prefix +
2308
- "<function TestSingleDispatch.test_invalid_registrations.<locals>._"
2307
+ self .assertTrue (str (exc .exception ).startswith (
2308
+ "Invalid annotation for 'arg'."
2309
+ ))
2310
+ self .assertTrue (str (exc .exception ).endswith (
2311
+ 'typing.Iterable[str] is not a class.'
2309
2312
))
2310
- self .assertTrue (str (exc .exception ).endswith (msg_suffix ))
2311
2313
2312
2314
def test_invalid_positional_argument (self ):
2313
2315
@functools .singledispatch
You can’t perform that action at this time.
0 commit comments