bpo-35252: Remove FIXME from test_functools (GH-10551)
diff --git a/Lib/functools.py b/Lib/functools.py
index 28d9f6f..c863341 100644
--- a/Lib/functools.py
+++ b/Lib/functools.py
@@ -861,9 +861,11 @@
# only import typing if annotation parsing is necessary
from typing import get_type_hints
argname, cls = next(iter(get_type_hints(func).items()))
- assert isinstance(cls, type), (
- f"Invalid annotation for {argname!r}. {cls!r} is not a class."
- )
+ if not isinstance(cls, type):
+ raise TypeError(
+ f"Invalid annotation for {argname!r}. "
+ f"{cls!r} is not a class."
+ )
registry[cls] = func
if cache_token is None and hasattr(cls, '__abstractmethods__'):
cache_token = get_cache_token()
diff --git a/Lib/test/test_functools.py b/Lib/test/test_functools.py
index 85c65d1..b89d779 100644
--- a/Lib/test/test_functools.py
+++ b/Lib/test/test_functools.py
@@ -2355,9 +2355,6 @@
))
self.assertTrue(str(exc.exception).endswith(msg_suffix))
- # FIXME: The following will only work after PEP 560 is implemented.
- return
-
with self.assertRaises(TypeError) as exc:
@i.register
def _(arg: typing.Iterable[str]):
@@ -2366,10 +2363,12 @@
# types from `typing`. Instead, annotate with regular types
# or ABCs.
return "I annotated with a generic collection"
- self.assertTrue(str(exc.exception).startswith(msg_prefix +
- "<function TestSingleDispatch.test_invalid_registrations.<locals>._"
+ self.assertTrue(str(exc.exception).startswith(
+ "Invalid annotation for 'arg'."
))
- self.assertTrue(str(exc.exception).endswith(msg_suffix))
+ self.assertTrue(str(exc.exception).endswith(
+ 'typing.Iterable[str] is not a class.'
+ ))
def test_invalid_positional_argument(self):
@functools.singledispatch