Call super in Generic.__init_subclass__ (#6356)
This commit is contained in:
parent
2eeac269dd
commit
ee566fe526
|
@ -1232,6 +1232,25 @@ class GenericTests(BaseTestCase):
|
|||
class C(List[int], B): ...
|
||||
self.assertEqual(C.__mro__, (C, list, B, Generic, object))
|
||||
|
||||
def test_init_subclass_super_called(self):
|
||||
class FinalException(Exception):
|
||||
pass
|
||||
|
||||
class Final:
|
||||
def __init_subclass__(cls, **kwargs) -> None:
|
||||
for base in cls.__bases__:
|
||||
if base is not Final and issubclass(base, Final):
|
||||
raise FinalException(base)
|
||||
super().__init_subclass__(**kwargs)
|
||||
class Test(Generic[T], Final):
|
||||
pass
|
||||
with self.assertRaises(FinalException):
|
||||
class Subclass(Test):
|
||||
pass
|
||||
with self.assertRaises(FinalException):
|
||||
class Subclass(Test[int]):
|
||||
pass
|
||||
|
||||
def test_nested(self):
|
||||
|
||||
G = Generic
|
||||
|
|
|
@ -850,6 +850,7 @@ class Generic:
|
|||
return _GenericAlias(cls, params)
|
||||
|
||||
def __init_subclass__(cls, *args, **kwargs):
|
||||
super().__init_subclass__(*args, **kwargs)
|
||||
tvars = []
|
||||
if '__orig_bases__' in cls.__dict__:
|
||||
error = Generic in cls.__orig_bases__
|
||||
|
|
Loading…
Reference in New Issue