Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
ee566fe5
Commit
ee566fe5
authored
Apr 04, 2018
by
Ivan Levkivskyi
Committed by
GitHub
Apr 04, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Call super in Generic.__init_subclass__ (#6356)
parent
2eeac269
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
0 deletions
+20
-0
Lib/test/test_typing.py
Lib/test/test_typing.py
+19
-0
Lib/typing.py
Lib/typing.py
+1
-0
No files found.
Lib/test/test_typing.py
View file @
ee566fe5
...
...
@@ -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
...
...
Lib/typing.py
View file @
ee566fe5
...
...
@@ -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__
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment