summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
author傅立业(Chris Fu) <17433201@qq.com>2024-03-29 00:19:20 (GMT)
committerGitHub <noreply@github.com>2024-03-29 00:19:20 (GMT)
commit8eec7ed714e65d616573b7331780b0aa43c6ed6a (patch)
tree895e92a936693c7ec970fbe72c4742cf59925c48 /Lib/test
parenta17f313e3958e825db9a83594c8471a984316536 (diff)
downloadcpython-8eec7ed714e65d616573b7331780b0aa43c6ed6a.zip
cpython-8eec7ed714e65d616573b7331780b0aa43c6ed6a.tar.gz
cpython-8eec7ed714e65d616573b7331780b0aa43c6ed6a.tar.bz2
gh-117110: Fix subclasses of typing.Any with custom constructors (#117111)
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_typing.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py
index 54c7b97..927f74e 100644
--- a/Lib/test/test_typing.py
+++ b/Lib/test/test_typing.py
@@ -140,6 +140,26 @@ class AnyTests(BaseTestCase):
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()