merge 3.5 (closes #24806)

This commit is contained in:
Benjamin Peterson 2015-10-06 19:42:46 -07:00
commit cdae2cb88a
3 changed files with 40 additions and 6 deletions

View File

@ -3798,6 +3798,37 @@ order (MRO) for bases """
else: else:
assert 0, "best_base calculation found wanting" 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): def test_mutable_bases_with_failing_mro(self):
# Testing mutable bases with failing mro... # Testing mutable bases with failing mro...

View File

@ -10,6 +10,9 @@ Release date: XXXX-XX-XX
Core and Builtins Core and Builtins
----------------- -----------------
- Issue #24806: Prevent builtin types that are not allowed to be subclassed from
being subclassed through multiple inheritance.
* Issue #25301: The UTF-8 decoder is now up to 15 times as fast for error * Issue #25301: The UTF-8 decoder is now up to 15 times as fast for error
handlers: ``ignore``, ``replace`` and ``surrogateescape``. handlers: ``ignore``, ``replace`` and ``surrogateescape``.

View File

@ -1973,6 +1973,12 @@ best_base(PyObject *bases)
if (PyType_Ready(base_i) < 0) if (PyType_Ready(base_i) < 0)
return NULL; 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); candidate = solid_base(base_i);
if (winner == NULL) { if (winner == NULL) {
winner = candidate; winner = candidate;
@ -2353,12 +2359,6 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds)
if (base == NULL) { if (base == NULL) {
goto error; 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); dict = PyDict_Copy(orig_dict);
if (dict == NULL) if (dict == NULL)