[Python-checkins] CVS: python/dist/src/Objects descrobject.c,2.18,2.19

Guido van Rossum gvanrossum@users.sourceforge.net
2001年12月10日 10:00:17 -0800


Update of /cvsroot/python/python/dist/src/Objects
In directory usw-pr-cvs1:/tmp/cvs-serv14670
Modified Files:
	descrobject.c 
Log Message:
property_descr_get(): Fix a curious bug in the property() type: when
no get function was defined, the property's doc string was
inaccessible. This was because the test for prop_get was made
*before* the test for a NULL/None object argument.
Also changed the property class defined in Python in a comment to test
for NULL to decide between get and delete; this makes it less Python
but then, assigning None to a property doesn't delete it!
Index: descrobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/descrobject.c,v
retrieving revision 2.18
retrieving revision 2.19
diff -C2 -d -r2.18 -r2.19
*** descrobject.c	2001年10月22日 00:43:43	2.18
--- descrobject.c	2001年12月10日 18:00:15	2.19
***************
*** 912,916 ****
 
 	def __get__(self, inst, type=None):
! 	 if self.__get is None:
 		raise AttributeError, "unreadable attribute"
 	 if inst is None:
--- 912,916 ----
 
 	def __get__(self, inst, type=None):
! 	 if self.__get is NULL:
 		raise AttributeError, "unreadable attribute"
 	 if inst is None:
***************
*** 964,974 ****
 	propertyobject *gs = (propertyobject *)self;
 
- 	if (gs->prop_get == NULL) {
- 		PyErr_SetString(PyExc_AttributeError, "unreadable attribute");
- 		return NULL;
- 	}
 	if (obj == NULL || obj == Py_None) {
 		Py_INCREF(self);
 		return self;
 	}
 	return PyObject_CallFunction(gs->prop_get, "(O)", obj);
--- 964,974 ----
 	propertyobject *gs = (propertyobject *)self;
 
 	if (obj == NULL || obj == Py_None) {
 		Py_INCREF(self);
 		return self;
+ 	}
+ 	if (gs->prop_get == NULL) {
+ 		PyErr_SetString(PyExc_AttributeError, "unreadable attribute");
+ 		return NULL;
 	}
 	return PyObject_CallFunction(gs->prop_get, "(O)", obj);

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