Skip to content
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

gh-117110: Fix subclasses of typing.Any with custom constructors #117111

Merged
merged 5 commits into from
Mar 29, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
move test and add a second test
  • Loading branch information
AlexWaygood authored Mar 21, 2024
commit 60179564c987309bbbe3822a3272e26bdf00ade0
26 changes: 20 additions & 6 deletions Lib/test/test_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,26 @@ class MockSomething(Something, Mock): pass
self.assertIsInstance(ms, Something)
self.assertIsInstance(ms, Mock)

def test_subclassing_with_custom_constructor(self):
class Sub(Any):
def __init__(self, *args, **kwargs): pass
# The instantiation must not fail.
Sub(0, s="")

def test_multiple_inheritance_with_custom_constructors(self):
class Foo:
def __init__(self, x):
self.x = x

class Bar(Any, Foo):
def __init__(self, x, y):
self.y = y
super().__init__(x)

b = Bar(1, 2)
self.assertEqual(b.x, 1)
self.assertEqual(b.y, 2)

def test_cannot_instantiate(self):
with self.assertRaises(TypeError):
Any()
Expand All @@ -152,12 +172,6 @@ def test_any_works_with_alias(self):
typing.Pattern[Any]
typing.IO[Any]

def test_subclass_can_instantiate_with_arguments(self):
class Sub(Any):
def __init__(self, *args, **kwargs): pass
# The instantiation must not fail.
Sub(0, s="")


class BottomTypeTestsMixin:
bottom_type: ClassVar[Any]
Expand Down
Loading