summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2003-04-16 19:40:58 (GMT)
committerGuido van Rossum <guido@python.org>2003-04-16 19:40:58 (GMT)
commit76ba09fd81246c21f0de25f559d4da47b457f2e2 (patch)
treecd59c1827922a956b1ed047b4f21c6ee47d8ec01 /Objects
parent954bcf5fe0d44f224c404628b0966bc63277548a (diff)
downloadcpython-76ba09fd81246c21f0de25f559d4da47b457f2e2.zip
cpython-76ba09fd81246c21f0de25f559d4da47b457f2e2.tar.gz
cpython-76ba09fd81246c21f0de25f559d4da47b457f2e2.tar.bz2
- super() no longer ignores data descriptors, except __class__. See
the thread started at http://mail.python.org/pipermail/python-dev/2003-April/034338.html
Diffstat (limited to 'Objects')
-rw-r--r--Objects/typeobject.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index 8f9deae..d45ee89 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -5359,8 +5359,17 @@ static PyObject *
super_getattro(PyObject *self, PyObject *name)
{
superobject *su = (superobject *)self;
+ int skip = su->obj_type == NULL;
- if (su->obj_type != NULL) {
+ if (!skip) {
+ /* We want __class__ to return the class of the super object
+ (i.e. super, or a subclass), not the class of su->obj. */
+ skip = (PyString_Check(name) &&
+ PyString_GET_SIZE(name) == 9 &&
+ strcmp(PyString_AS_STRING(name), "__class__") == 0);
+ }
+
+ if (!skip) {
PyObject *mro, *res, *tmp, *dict;
PyTypeObject *starttype;
descrgetfunc f;
@@ -5390,9 +5399,6 @@ super_getattro(PyObject *self, PyObject *name)
else
continue;
res = PyDict_GetItem(dict, name);
- /* Skip data descriptors because when obj_type is a
- metaclass, we don't want to return its __class__
- descriptor. See supers() in test_descr.py. */
if (res != NULL && !PyDescr_IsData(res)) {
Py_INCREF(res);
f = res->ob_type->tp_descr_get;