8000 bpo-35252: Remove FIXME from test_functools (GH-10551) · python/cpython@d673810 · GitHub
[go: up one dir, main page]

Skip to content

Commit d673810

Browse files
lysnikolaouambv
authored andcommitted
bpo-35252: Remove FIXME from test_functools (GH-10551)
1 parent 287b84d commit d673810

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

Lib/functools.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -861,9 +861,11 @@ def register(cls, func=None):
861861
# only import typing if annotation parsing is necessary
862862
from typing import get_type_hints
863863
argname, cls = next(iter(get_type_hints(func).items()))
864-
assert isinstance(cls, type), (
865-
f"Invalid annotation for {argname!r}. {cls!r} is not a class."
866-
)
864+
if not isinstance(cls, type):
865+
raise TypeError(
866+
f"Invalid annotation for {argname!r}. "
867+
f"{cls!r} is not a class."
868+
)
867869
registry[cls] = func
868870
if cache_token is None and hasattr(cls, '__abstractmethods__'):
869871
cache_token = get_cache_token()

Lib/test/test_functools.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2355,9 +2355,6 @@ def _(arg):
23552355
))
23562356
self.assertTrue(str(exc.exception).endswith(msg_suffix))
23572357

2358-
# FIXME: The following will only work after PEP 560 is implemented.
2359-
return
2360-
23612358
with self.assertRaises(TypeError) as exc:
23622359
@i.register
23632360
def _(arg: typing.Iterable[str]):
@@ -2366,10 +2363,12 @@ def _(arg: typing.Iterable[str]):
23662363
# types from `typing`. Instead, annotate with regular types
23672364
# or ABCs.
23682365
return "I annotated with a generic collection"
2369-
self.assertTrue(str(exc.exception).startswith(msg_prefix +
2370-
"<function TestSingleDispatch.test_invalid_registrations.<locals>._"
2366+
self.assertTrue(str(exc.exception).startswith(
2367+
"Invalid annotation for 'arg'."
2368+
))
2369+
self.assertTrue(str(exc.exception).endswith(
2370+
'typing.Iterable[str] is not a class.'
23712371
))
2372-
self.assertTrue(str(exc.exception).endswith(msg_suffix))
23732372

23742373
def test_invalid_positional_argument(self):
23752374
@functools.singledispatch
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Throw a TypeError instead of an AssertionError when using an invalid type annotation with singledispatch.

0 commit comments

Comments
 (0)
0