[Python-checkins] CVS: python/dist/src/Objects object.c,2.124.4.23,2.124.4.24

Guido van Rossum gvanrossum@users.sourceforge.net
Fri, 13 Jul 2001 14:47:40 -0700


Update of /cvsroot/python/python/dist/src/Objects
In directory usw-pr-cvs1:/tmp/cvs-serv22194

Modified Files:
      Tag: descr-branch
	object.c 
Log Message:
PyObject_SetAttr(): be more careful when raising an exception because
there's no tp_getattr[o] slot.  First, change this into a TypeError
rather than an AttributeError (it was also a TypeError in 2.1 and
before).  Second, issue a different error message when the type has no
tp_getattr[o] slot than when it does.  Third, in all cases mention
both the operation (assign to or del) and the attribute name.


Index: object.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/object.c,v
retrieving revision 2.124.4.23
retrieving revision 2.124.4.24
diff -C2 -r2.124.4.23 -r2.124.4.24
*** object.c	2001/07/07 22:55:30	2.124.4.23
--- object.c	2001/07/13 21:47:38	2.124.4.24
***************
*** 1104,1110 ****
  	}
  	Py_DECREF(name);
! 	PyErr_Format(PyExc_AttributeError,
! 		     "'%.50s' object has no attribute '%.400s'",
! 		     tp->tp_name, PyString_AS_STRING(name));
  	return -1;
  }
--- 1104,1121 ----
  	}
  	Py_DECREF(name);
! 	if (tp->tp_getattr == NULL && tp->tp_getattro == NULL)
! 		PyErr_Format(PyExc_TypeError,
! 			     "'%.100s' object has no attributes "
! 			     "(%s .%.100s)",
! 			     tp->tp_name,
! 			     value==NULL ? "del" : "assign to",
! 			     PyString_AS_STRING(name));
! 	else
! 		PyErr_Format(PyExc_TypeError,
! 			     "'%.100s' object has only read-only attributes "
! 			     "(%s .%.100s)",
! 			     tp->tp_name,
! 			     value==NULL ? "del" : "assign to",
! 			     PyString_AS_STRING(name));
  	return -1;
  }