[Python-checkins] CVS: python/dist/src/Objects classobject.c,2.152,2.153

Guido van Rossum gvanrossum@users.sourceforge.net
2001年10月21日 19:00:12 -0700


Update of /cvsroot/python/python/dist/src/Objects
In directory usw-pr-cvs1:/tmp/cvs-serv1010/Objects
Modified Files:
	classobject.c 
Log Message:
Fix for SF bug #472940: can't getattr() attribute shown by dir()
There really isn't a good reason for instance method objects to have
their own __dict__, __doc__ and __name__ properties that just delegate
the request to the function (callable); the default attribute behavior
already does this.
The test suite had to be fixed because the error changes from
TypeError to AttributeError.
Index: classobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/classobject.c,v
retrieving revision 2.152
retrieving revision 2.153
diff -C2 -d -r2.152 -r2.153
*** classobject.c	2001年10月17日 20:26:38	2.152
--- classobject.c	2001年10月22日 02:00:09	2.153
***************
*** 2020,2050 ****
 };
 
- /* __dict__, __doc__ and __name__ are retrieved from im_func */
- 
- static PyObject *
- im_get_dict(PyMethodObject *im)
- {
- 	return PyObject_GetAttrString(im->im_func, "__dict__");
- }
- 
- static PyObject *
- im_get_doc(PyMethodObject *im)
- {
- 	return PyObject_GetAttrString(im->im_func, "__doc__");
- }
- 
- static PyObject *
- im_get_name(PyMethodObject *im)
- {
- 	return PyObject_GetAttrString(im->im_func, "__name__");
- }
- 
- static PyGetSetDef instancemethod_getsetlist[] = {
- 	{"__dict__", (getter)im_get_dict, NULL, "same as im_func.__dict__"},
- 	{"__doc__", (getter)im_get_doc, NULL, "same as im_func.__doc__"},
- 	{"__name__", (getter)im_get_name, NULL, "same as im_func.__name__"},
- 	{NULL} /* Sentinel */
- };
- 
 /* The getattr() implementation for PyMethod objects is similar to
 PyObject_GenericGetAttr(), but instead of looking in __dict__ it
--- 2020,2023 ----
***************
*** 2351,2355 ****
 	0,					/* tp_methods */
 	instancemethod_memberlist,		/* tp_members */
! 	instancemethod_getsetlist,		/* tp_getset */
 	0,					/* tp_base */
 	0,					/* tp_dict */
--- 2324,2328 ----
 	0,					/* tp_methods */
 	instancemethod_memberlist,		/* tp_members */
! 	0,					/* tp_getset */
 	0,					/* tp_base */
 	0,					/* tp_dict */

AltStyle によって変換されたページ (->オリジナル) /