summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIvan Levkivskyi <levkivskyi@gmail.com>2018-04-04 16:00:15 (GMT)
committerGitHub <noreply@github.com>2018-04-04 16:00:15 (GMT)
commitee566fe526f3d069aa313578ee81ca6cbc25ff52 (patch)
treebc494e11c8f60ec249e3b58097b40f0bfcbcad5a
parent2eeac269dd1e04a2a179384576986c3e47895ee0 (diff)
downloadcpython-ee566fe526f3d069aa313578ee81ca6cbc25ff52.zip
cpython-ee566fe526f3d069aa313578ee81ca6cbc25ff52.tar.gz
cpython-ee566fe526f3d069aa313578ee81ca6cbc25ff52.tar.bz2
Call super in Generic.__init_subclass__ (#6356)
-rw-r--r--Lib/test/test_typing.py19
-rw-r--r--Lib/typing.py1
2 files changed, 20 insertions, 0 deletions
diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py
index 09e39fe..b12e5ea 100644
--- a/Lib/test/test_typing.py
+++ b/Lib/test/test_typing.py
@@ -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
diff --git a/Lib/typing.py b/Lib/typing.py
index 510574c..3ac3b93 100644
--- a/Lib/typing.py
+++ b/Lib/typing.py
@@ -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__