mirror of
https://github.com/python/cpython.git
synced 2025-11-03 11:23:31 +00:00
(Merge 3.1) Issue #9756: When calling a method descriptor or a slot wrapper
descriptor, the check of the object type doesn't read the __class__ attribute anymore. Fix a crash if a class override its __class__ attribute (e.g. a proxy of the str type).
This commit is contained in:
commit
d9561318d8
3 changed files with 27 additions and 3 deletions
|
|
@ -4235,6 +4235,22 @@ order (MRO) for bases """
|
||||||
with self.assertRaises(AttributeError):
|
with self.assertRaises(AttributeError):
|
||||||
del X.__abstractmethods__
|
del X.__abstractmethods__
|
||||||
|
|
||||||
|
def test_proxy_call(self):
|
||||||
|
class FakeStr:
|
||||||
|
__class__ = str
|
||||||
|
|
||||||
|
fake_str = FakeStr()
|
||||||
|
# isinstance() reads __class__
|
||||||
|
self.assertTrue(isinstance(fake_str, str))
|
||||||
|
|
||||||
|
# call a method descriptor
|
||||||
|
with self.assertRaises(TypeError):
|
||||||
|
str.split(fake_str)
|
||||||
|
|
||||||
|
# call a slot wrapper descriptor
|
||||||
|
with self.assertRaises(TypeError):
|
||||||
|
str.__add__(fake_str, "abc")
|
||||||
|
|
||||||
|
|
||||||
class DictProxyTests(unittest.TestCase):
|
class DictProxyTests(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,11 @@ What's New in Python 3.2.1?
|
||||||
Core and Builtins
|
Core and Builtins
|
||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
|
- Issue #9756: When calling a method descriptor or a slot wrapper descriptor,
|
||||||
|
the check of the object type doesn't read the __class__ attribute anymore.
|
||||||
|
Fix a crash if a class override its __class__ attribute (e.g. a proxy of the
|
||||||
|
str type).
|
||||||
|
|
||||||
- Issue #10914: Initialize correctly the filesystem codec when creating a new
|
- Issue #10914: Initialize correctly the filesystem codec when creating a new
|
||||||
subinterpreter to fix a bootstrap issue with codecs implemented in Python, as
|
subinterpreter to fix a bootstrap issue with codecs implemented in Python, as
|
||||||
the ISO-8859-15 codec.
|
the ISO-8859-15 codec.
|
||||||
|
|
|
||||||
|
|
@ -226,7 +226,8 @@ methoddescr_call(PyMethodDescrObject *descr, PyObject *args, PyObject *kwds)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
self = PyTuple_GET_ITEM(args, 0);
|
self = PyTuple_GET_ITEM(args, 0);
|
||||||
if (!PyObject_IsInstance(self, (PyObject *)PyDescr_TYPE(descr))) {
|
if (!_PyObject_RealIsSubclass((PyObject *)Py_TYPE(self),
|
||||||
|
(PyObject *)PyDescr_TYPE(descr))) {
|
||||||
PyErr_Format(PyExc_TypeError,
|
PyErr_Format(PyExc_TypeError,
|
||||||
"descriptor '%V' "
|
"descriptor '%V' "
|
||||||
"requires a '%.100s' object "
|
"requires a '%.100s' object "
|
||||||
|
|
@ -284,7 +285,8 @@ wrapperdescr_call(PyWrapperDescrObject *descr, PyObject *args, PyObject *kwds)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
self = PyTuple_GET_ITEM(args, 0);
|
self = PyTuple_GET_ITEM(args, 0);
|
||||||
if (!PyObject_IsInstance(self, (PyObject *)PyDescr_TYPE(descr))) {
|
if (!_PyObject_RealIsSubclass((PyObject *)Py_TYPE(self),
|
||||||
|
(PyObject *)PyDescr_TYPE(descr))) {
|
||||||
PyErr_Format(PyExc_TypeError,
|
PyErr_Format(PyExc_TypeError,
|
||||||
"descriptor '%V' "
|
"descriptor '%V' "
|
||||||
"requires a '%.100s' object "
|
"requires a '%.100s' object "
|
||||||
|
|
@ -1065,7 +1067,8 @@ PyWrapper_New(PyObject *d, PyObject *self)
|
||||||
|
|
||||||
assert(PyObject_TypeCheck(d, &PyWrapperDescr_Type));
|
assert(PyObject_TypeCheck(d, &PyWrapperDescr_Type));
|
||||||
descr = (PyWrapperDescrObject *)d;
|
descr = (PyWrapperDescrObject *)d;
|
||||||
assert(PyObject_IsInstance(self, (PyObject *)PyDescr_TYPE(descr)));
|
assert(_PyObject_RealIsSubclass((PyObject *)Py_TYPE(self),
|
||||||
|
(PyObject *)PyDescr_TYPE(descr)));
|
||||||
|
|
||||||
wp = PyObject_GC_New(wrapperobject, &wrappertype);
|
wp = PyObject_GC_New(wrapperobject, &wrappertype);
|
||||||
if (wp != NULL) {
|
if (wp != NULL) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue