]> granicus.if.org Git - python/commitdiff
classobject.c:instancemethod_descr_get(): when a bound method is
authorGuido van Rossum <guido@python.org>
Thu, 16 Aug 2001 20:41:56 +0000 (20:41 +0000)
committerGuido van Rossum <guido@python.org>
Thu, 16 Aug 2001 20:41:56 +0000 (20:41 +0000)
assigned to a class variable and then accessed via an instance, it
should not be rebound.

test_descr.py:methods(): test for the condition above.

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

index 4d1f817e1ff62d5f60ba46a3ece020e6331fabc6..f524dbaa5fdcfa85af1e7d141acdc0192a0ae9de 100644 (file)
@@ -862,7 +862,7 @@ def methods():
     d2 = D(2)
     verify(d2.foo() == 2)
     verify(d2.boo() == 2)
-    verify(d2.goo() == 2)
+    verify(d2.goo() == 1)
 
 def specials():
     # Test operators like __hash__ for which a built-in default exists
index 255a432f53316d20265760d32c540f1bfcccb032..82eb1d51ed9c9177884459f5972da187e578cf20 100644 (file)
@@ -2196,6 +2196,11 @@ instancemethod_call(PyObject *func, PyObject *arg, PyObject *kw)
 static PyObject *
 instancemethod_descr_get(PyObject *meth, PyObject *obj, PyObject *type)
 {
+       if (PyMethod_GET_SELF(meth) != NULL) {
+               /* Don't rebind an already bound method */
+               Py_INCREF(meth);
+               return meth;
+       }
        if (obj == Py_None)
                obj = NULL;
        return PyMethod_New(PyMethod_GET_FUNCTION(meth), obj, type);