summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2015-10-07 02:42:02 (GMT)
committerBenjamin Peterson <benjamin@python.org>2015-10-07 02:42:02 (GMT)
commit59dc696821da8888b5ac1b86c6c0fd4202f92b39 (patch)
tree99f4e3de908252de56f29239b99b9de954cc40fc
parent479ac6654c94ee16fe2bfa2acec8d3fe86ef1381 (diff)
parentbd6c41a185ad4a2db9ad693a79496429e2f8d7ee (diff)
downloadcpython-59dc696821da8888b5ac1b86c6c0fd4202f92b39.zip
cpython-59dc696821da8888b5ac1b86c6c0fd4202f92b39.tar.gz
cpython-59dc696821da8888b5ac1b86c6c0fd4202f92b39.tar.bz2
merge 3.4 (#24806)
-rw-r--r--Lib/test/test_descr.py31
-rw-r--r--Misc/NEWS3
-rw-r--r--Objects/typeobject.c12
3 files changed, 40 insertions, 6 deletions
diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py
index c74ebae..4fd9211 100644
--- a/Lib/test/test_descr.py
+++ b/Lib/test/test_descr.py
@@ -3798,6 +3798,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...
diff --git a/Misc/NEWS b/Misc/NEWS
index 66bf5b9..de56df2 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -11,6 +11,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
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index bb83530..06ce899 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -1965,6 +1965,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;
@@ -2345,12 +2351,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)