From: Phillip J. Eby Date: Thu, 25 Mar 2004 02:19:34 +0000 (+0000) Subject: Ensure super() lookup of descriptor from classmethod works (SF #743627) X-Git-Tag: v2.4a1~580 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=91a968af7640348d92011e305127d5968958aff4;p=thirdparty%2FPython%2Fcpython.git Ensure super() lookup of descriptor from classmethod works (SF #743627) --- diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py index ccb9fe613b4e..a224bb90fd94 100644 --- a/Lib/test/test_descr.py +++ b/Lib/test/test_descr.py @@ -2064,6 +2064,20 @@ def supers(): vereq(dd.x, "hello") vereq(super(DDsub, dd).x, 42) + # Ensure that super() lookup of descriptor from classmethod + # works (SF ID# 743627) + + class Base(object): + aProp = property(lambda self: "foo") + + class Sub(Base): + def test(klass): + return super(Sub,klass).aProp + test = classmethod(test) + + veris(Sub.test(), Base.aProp) + + def inherits(): if verbose: print "Testing inheritance from basic types..." diff --git a/Objects/typeobject.c b/Objects/typeobject.c index f26ddd6bd3b7..209ec329d7bc 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -5537,7 +5537,14 @@ super_getattro(PyObject *self, PyObject *name) Py_INCREF(res); f = res->ob_type->tp_descr_get; if (f != NULL) { - tmp = f(res, su->obj, + tmp = f(res, + /* Only pass 'obj' param if + this is instance-mode super + (See SF ID #743627) + */ + (su->obj==su->obj_type + ? (PyObject *)NULL + : su->obj), (PyObject *)starttype); Py_DECREF(res); res = tmp;