Mercurial > cpython-lru_cache-weakref
diff Objects/classobject.c @ 19323:261e28e7fa01 legacy-trunk
classobject.c:instancemethod_descr_get(): when a bound method is
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.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Thu, 16 Aug 2001 20:41:56 +0000 |
| parents | f10b68eceefc |
| children | 0613fa57ae6d |
line wrap: on
line diff
--- a/Objects/classobject.c Thu Aug 16 20:39:24 2001 +0000 +++ b/Objects/classobject.c Thu Aug 16 20:41:56 2001 +0000 @@ -2196,6 +2196,11 @@ 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);
