8000 bpo-46998: Allow subclassing Any at runtime by hauntsaninja · Pull Request #31841 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-46998: Allow subclassing Any at runtime #31841

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 15 commits into from
Apr 5, 2022
Prev Previous commit
Next Next commit
remove functools checks
  • Loading branch information
hauntsaninja committed Mar 13, 2022
commit 771f492f76f72b0451219500f3d71aeb54eb2308
8 changes: 0 additions & 8 deletions Lib/test/test_functools.py
Original file line number Diff line number Diff line change
Expand Up @@ -2802,8 +2802,6 @@ def f(arg):
f.register(list[int] | str, lambda arg: "types.UnionTypes(types.GenericAlias)")
with self.assertRaisesRegex(TypeError, "Invalid first argument to "):
f.register(typing.List[float] | bytes, lambda arg: "typing.Union[typing.GenericAlias]")
with self.assertRaisesRegex(TypeError, "Invalid first argument to "):
f.register(typing.Any, lambda arg: "typing.Any")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be worth forbidding explicitly because the behavior could be quite unintuitive. Happy to leave that decision to the functools maintainer though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ambv, do you have any thoughts on the bits of this PR that touch singledispatch?


self.assertEqual(f([1]), "default")
self.assertEqual(f([1.0]), "default")
Expand All @@ -2823,8 +2821,6 @@ def f(arg):
f.register(list[int] | str)
with self.assertRaisesRegex(TypeError, "Invalid first argument to "):
f.register(typing.List[int] | str)
with self.assertRaisesRegex(TypeError, "Invalid first argument to "):
f.register(typing.Any)

def test_register_genericalias_annotation(self):
@functools.singledispatch
Expand All @@ -2847,10 +2843,6 @@ def _(arg: list[int] | str):
@f.register
def _(arg: typing.List[float] | bytes):
return "typing.Union[typing.GenericAlias]"
with self.assertRaisesRegex(TypeError, "Invalid annotation for 'arg'"):
@f.register
def _(arg: typing.Any):
return "typing.Any"

self.assertEqual(f([1]), "default")
self.assertEqual(f([1.0]), "default")
Expand Down
0