cpython: c5e6f997730e (original) (raw)
Mercurial > cpython
changeset 69741:c5e6f997730e 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). [#9756]
Victor Stinner victor.stinner@haypocalc.com | |
---|---|
date | Sun, 01 May 2011 23:19:15 +0200 |
parents | c57fdce01eb8 |
children | 4fc04f6a0731 0db11682ea45 |
files | Lib/test/test_descr.py Misc/NEWS Objects/descrobject.c |
diffstat | 3 files changed, 27 insertions(+), 3 deletions(-)[+] [-] Lib/test/test_descr.py 16 Misc/NEWS 5 Objects/descrobject.c 9 |
line wrap: on
line diff
--- a/Lib/test/test_descr.py +++ b/Lib/test/test_descr.py @@ -4235,6 +4235,22 @@ order (MRO) for bases """ with self.assertRaises(AttributeError): del X.abstractmethods
fake_str = FakeStr()[](#l1.11)
# isinstance() reads __class__[](#l1.12)
self.assertTrue(isinstance(fake_str, str))[](#l1.13)
# call a method descriptor[](#l1.15)
with self.assertRaises(TypeError):[](#l1.16)
str.split(fake_str)[](#l1.17)
# call a slot wrapper descriptor[](#l1.19)
with self.assertRaises(TypeError):[](#l1.20)
str.__add__(fake_str, "abc")[](#l1.21)
+ class DictProxyTests(unittest.TestCase): def setUp(self):
--- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,11 @@ What's New in Python 3.1.4? 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). +
--- a/Objects/descrobject.c +++ b/Objects/descrobject.c @@ -226,7 +226,8 @@ methoddescr_call(PyMethodDescrObject *de return NULL; } self = PyTuple_GET_ITEM(args, 0);
- if (!_PyObject_RealIsSubclass((PyObject *)Py_TYPE(self),
(PyObject *)(descr->d_type))) {[](#l3.9) PyErr_Format(PyExc_TypeError,[](#l3.10) "descriptor '%V' "[](#l3.11) "requires a '%.100s' object "[](#l3.12)
@@ -284,7 +285,8 @@ wrapperdescr_call(PyWrapperDescrObject * return NULL; } self = PyTuple_GET_ITEM(args, 0);
- if (!_PyObject_RealIsSubclass((PyObject *)Py_TYPE(self),
(PyObject *)(descr->d_type))) {[](#l3.19) PyErr_Format(PyExc_TypeError,[](#l3.20) "descriptor '%V' "[](#l3.21) "requires a '%.100s' object "[](#l3.22)
@@ -1065,7 +1067,8 @@ PyWrapper_New(PyObject *d, PyObject *sel assert(PyObject_TypeCheck(d, &PyWrapperDescr_Type)); descr = (PyWrapperDescrObject *)d;
wp = PyObject_GC_New(wrapperobject, &wrappertype); if (wp != NULL) {