]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Ensure super() lookup of descriptor from classmethod works (SF ID# 743627)
authorPhillip J. Eby <pje@telecommunity.com>
Thu, 25 Mar 2004 02:36:29 +0000 (02:36 +0000)
committerPhillip J. Eby <pje@telecommunity.com>
Thu, 25 Mar 2004 02:36:29 +0000 (02:36 +0000)
(Backport to 2.3 maintenance branch)

Lib/test/test_descr.py
Objects/typeobject.c

index b3336d1fc8d784f53714dee8cc0c4395caff28eb..2907d04dea4e51e9ec6bce8787d3167ced51971c 100644 (file)
@@ -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..."
 
index 149d2d0d8f356ac5ad6e90e20645e740abc31f03..81c2baee70171bcaadd9b061be55ab924d4b78ae 100644 (file)
@@ -5496,7 +5496,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;