Skip to content

bpo-35252: Remove FIXME from test_functools #10551

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions Lib/functools.py
Original file line number Diff line number Diff line change
Expand Up @@ -848,9 +848,11 @@ def register(cls, func=None):
# 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()
Expand Down
11 changes: 5 additions & 6 deletions Lib/test/test_functools.py
Original file line number Diff line number Diff line change
Expand Up @@ -2296,9 +2296,6 @@ def _(arg):
))
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]):
Expand All @@ -2307,10 +2304,12 @@ def _(arg: typing.Iterable[str]):
# 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(
'typing.Iterable[str] is not a class.'
))
self.assertTrue(str(exc.exception).endswith(msg_suffix))

def test_invalid_positional_argument(self):
@functools.singledispatch
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Throw a TypeError instead of an AssertionError when using an invalid type annotation with singledispatch.