gh-138010: Fix __init_subclass__ forwarding by warnings.deprecated (#138210)

This commit is contained in:
Brian Schubert 2025-09-05 16:44:50 -04:00 committed by GitHub
parent 8ed1d53e62
commit e2c038f5be
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 36 additions and 13 deletions

View file

@ -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