[Python-checkins] python/dist/src/Objects classobject.c, 2.173,
2.174
gvanrossum at users.sourceforge.net
gvanrossum at users.sourceforge.net
Sat Nov 22 18:55:52 EST 2003
Update of /cvsroot/python/python/dist/src/Objects
In directory sc8-pr-cvs1:/tmp/cvs-serv25128/Objects
Modified Files:
classobject.c
Log Message:
- When method objects have an attribute that can be satisfied either
by the function object or by the method object, the function
object's attribute usually wins. Christian Tismer pointed out that
that this is really a mistake, because this only happens for special
methods (like __reduce__) where the method object's version is
really more appropriate than the function's attribute. So from now
on, all method attributes will have precedence over function
attributes with the same name.
Index: classobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/classobject.c,v
retrieving revision 2.173
retrieving revision 2.174
diff -C2 -d -r2.173 -r2.174
*** classobject.c 28 Oct 2003 12:05:47 -0000 2.173
--- classobject.c 22 Nov 2003 23:55:50 -0000 2.174
***************
*** 2139,2147 ****
};
! /* The getattr() implementation for PyMethod objects is similar to
! PyObject_GenericGetAttr(), but instead of looking in __dict__ it
! asks im_self for the attribute. Then the error handling is a bit
! different because we want to preserve the exception raised by the
! delegate, unless we have an alternative from our class. */
static PyObject *
--- 2139,2163 ----
};
! /* Christian Tismer argued convincingly that method attributes should
! (nearly) always override function attributes.
! The one exception is __doc__; there's a default __doc__ which
! should only be used for the class, not for instances */
!
! static PyObject *
! instancemethod_get_doc(PyMethodObject *im, void *context)
! {
! static PyObject *docstr;
! if (docstr == NULL) {
! docstr= PyString_InternFromString("__doc__");
! if (docstr == NULL)
! return NULL;
! }
! return PyObject_GetAttr(im->im_func, docstr);
! }
!
! static PyGetSetDef instancemethod_getset[] = {
! {"__doc__", (getter)instancemethod_get_doc, NULL, NULL},
! {0}
! };
static PyObject *
***************
*** 2150,2155 ****
PyMethodObject *im = (PyMethodObject *)obj;
PyTypeObject *tp = obj->ob_type;
! PyObject *descr = NULL, *res;
! descrgetfunc f = NULL;
if (PyType_HasFeature(tp, Py_TPFLAGS_HAVE_CLASS)) {
--- 2166,2170 ----
PyMethodObject *im = (PyMethodObject *)obj;
PyTypeObject *tp = obj->ob_type;
! PyObject *descr = NULL;
if (PyType_HasFeature(tp, Py_TPFLAGS_HAVE_CLASS)) {
***************
*** 2161,2188 ****
}
- f = NULL;
if (descr != NULL) {
! f = TP_DESCR_GET(descr->ob_type);
! if (f != NULL && PyDescr_IsData(descr))
return f(descr, obj, (PyObject *)obj->ob_type);
}
! res = PyObject_GetAttr(im->im_func, name);
! if (res != NULL || !PyErr_ExceptionMatches(PyExc_AttributeError))
! return res;
!
! if (f != NULL) {
! PyErr_Clear();
! return f(descr, obj, (PyObject *)obj->ob_type);
! }
!
! if (descr != NULL) {
! PyErr_Clear();
! Py_INCREF(descr);
! return descr;
! }
!
! assert(PyErr_Occurred());
! return NULL;
}
--- 2176,2190 ----
}
if (descr != NULL) {
! descrgetfunc f = TP_DESCR_GET(descr->ob_type);
! if (f != NULL)
return f(descr, obj, (PyObject *)obj->ob_type);
+ else {
+ Py_INCREF(descr);
+ return descr;
+ }
}
! return PyObject_GetAttr(im->im_func, name);
}
***************
*** 2491,2495 ****
0, /* tp_methods */
instancemethod_memberlist, /* tp_members */
! 0, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
--- 2493,2497 ----
0, /* tp_methods */
instancemethod_memberlist, /* tp_members */
! instancemethod_getset, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
More information about the Python-checkins
mailing list