mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
gh-138010: Fix __init_subclass__ forwarding by warnings.deprecated (#138210)
This commit is contained in:
parent
8ed1d53e62
commit
e2c038f5be
3 changed files with 36 additions and 13 deletions
|
|
@ -1863,6 +1863,25 @@ class D(C, x=3):
|
|||
|
||||
self.assertEqual(D.inited, 3)
|
||||
|
||||
def test_existing_init_subclass_in_sibling_base(self):
|
||||
@deprecated("A will go away soon")
|
||||
class A:
|
||||
pass
|
||||
class B:
|
||||
def __init_subclass__(cls, x):
|
||||
super().__init_subclass__()
|
||||
cls.inited = x
|
||||
|
||||
with self.assertWarnsRegex(DeprecationWarning, "A will go away soon"):
|
||||
class C(A, B, x=42):
|
||||
pass
|
||||
self.assertEqual(C.inited, 42)
|
||||
|
||||
with self.assertWarnsRegex(DeprecationWarning, "A will go away soon"):
|
||||
class D(B, A, x=42):
|
||||
pass
|
||||
self.assertEqual(D.inited, 42)
|
||||
|
||||
def test_init_subclass_has_correct_cls(self):
|
||||
init_subclass_saw = None
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue