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
bd6c41a1
Commit
bd6c41a1
authored
Oct 06, 2015
by
Benjamin Peterson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
prevent unacceptable bases from becoming bases through multiple inheritance (#24806)
parent
106ddf07
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
40 additions
and
6 deletions
+40
-6
Lib/test/test_descr.py
Lib/test/test_descr.py
+31
-0
Misc/NEWS
Misc/NEWS
+3
-0
Objects/typeobject.c
Objects/typeobject.c
+6
-6
No files found.
Lib/test/test_descr.py
View file @
bd6c41a1
...
...
@@ -3735,6 +3735,37 @@ order (MRO) for bases """
else
:
assert
0
,
"best_base calculation found wanting"
def
test_unsubclassable_types
(
self
):
with
self
.
assertRaises
(
TypeError
):
class
X
(
type
(
None
)):
pass
with
self
.
assertRaises
(
TypeError
):
class
X
(
object
,
type
(
None
)):
pass
with
self
.
assertRaises
(
TypeError
):
class
X
(
type
(
None
),
object
):
pass
class
O
(
object
):
pass
with
self
.
assertRaises
(
TypeError
):
class
X
(
O
,
type
(
None
)):
pass
with
self
.
assertRaises
(
TypeError
):
class
X
(
type
(
None
),
O
):
pass
class
X
(
object
):
pass
with
self
.
assertRaises
(
TypeError
):
X
.
__bases__
=
type
(
None
),
with
self
.
assertRaises
(
TypeError
):
X
.
__bases__
=
object
,
type
(
None
)
with
self
.
assertRaises
(
TypeError
):
X
.
__bases__
=
type
(
None
),
object
with
self
.
assertRaises
(
TypeError
):
X
.
__bases__
=
O
,
type
(
None
)
with
self
.
assertRaises
(
TypeError
):
X
.
__bases__
=
type
(
None
),
O
def
test_mutable_bases_with_failing_mro
(
self
):
# Testing mutable bases with failing mro...
...
...
Misc/NEWS
View file @
bd6c41a1
...
...
@@ -10,6 +10,9 @@ Release date: tba
Core and Builtins
-----------------
- Issue #24806: Prevent builtin types that are not allowed to be subclassed from
being subclassed through multiple inheritance.
- Issue #24848: Fixed a number of bugs in UTF-7 decoding of misformed data.
- Issue #25280: Import trace messages emitted in verbose (-v) mode are no
...
...
Objects/typeobject.c
View file @
bd6c41a1
...
...
@@ -1937,6 +1937,12 @@ best_base(PyObject *bases)
if
(
PyType_Ready
(
base_i
)
<
0
)
return
NULL
;
}
if
(
!
PyType_HasFeature
(
base_i
,
Py_TPFLAGS_BASETYPE
))
{
PyErr_Format
(
PyExc_TypeError
,
"type '%.100s' is not an acceptable base type"
,
base_i
->
tp_name
);
return
NULL
;
}
candidate
=
solid_base
(
base_i
);
if
(
winner
==
NULL
)
{
winner
=
candidate
;
...
...
@@ -2317,12 +2323,6 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds)
if
(
base
==
NULL
)
{
goto
error
;
}
if
(
!
PyType_HasFeature
(
base
,
Py_TPFLAGS_BASETYPE
))
{
PyErr_Format
(
PyExc_TypeError
,
"type '%.100s' is not an acceptable base type"
,
base
->
tp_name
);
goto
error
;
}
dict
=
PyDict_Copy
(
orig_dict
);
if
(
dict
==
NULL
)
...
...
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