]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Ensure super() lookup of descriptor from classmethod works (SF #743627)
authorPhillip J. Eby <pje@telecommunity.com>
Thu, 25 Mar 2004 02:19:34 +0000 (02:19 +0000)
committerPhillip J. Eby <pje@telecommunity.com>
Thu, 25 Mar 2004 02:19:34 +0000 (02:19 +0000)
Lib/test/test_descr.py
Objects/typeobject.c

index ccb9fe613b4e5e9e8a770d377fbf98f9a47c4a83..a224bb90fd94bac44b6213c7810ea661c5efa9fc 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 f26ddd6bd3b7bdbf6f51b33dedb2b56817d7a7ae..209ec329d7bc5dc50d201851b44582bb78a13090 100644 (file)
@@ -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;