[Patches] Change to attribute error message for instances.

Mark Hammond mhammond@skippinet.com.au
Mon, 10 Apr 2000 13:06:14 +1000


In line with a similar checkin to object.c a while ago, this patch
gives a more descriptive error message for an attribute error on a
class instance.  The message now looks like:

AttributeError: 'Descriptor' instance has no attribute
'GetReturnType'

[Maybe the module name would also be useful, but IMO this is fine
and a nice improvement]

Release info:

I confirm that, to the best of my knowledge and belief, this
contribution is free of any claims of third parties under copyright,
patent or other rights or interests ("claims").  To the extent that
I have any such claims, I hereby grant to CNRI a nonexclusive,
irrevocable, royalty-free, worldwide license to reproduce,
distribute, perform and/or display publicly, prepare derivative
versions, and otherwise use this contribution as part of the Python
software and its related documentation, or any derivative versions
thereof, at no cost to CNRI or its licensed users, and to authorize
others to do so.

I acknowledge that CNRI may, at its sole discretion, decide whether
or not to incorporate this contribution in the Python software and
its related documentation.  I further grant CNRI permission to use
my name and other identifying information provided to CNRI by me for
use in connection with the Python software and its related
documentation.

Mark.

diff -c -2 -r2.83 classobject.c
*** classobject.c	2000/02/28 15:03:15	2.83
--- classobject.c	2000/04/10 03:01:08
***************
*** 593,597 ****
  		v = class_lookup(inst->in_class, name, &class);
  		if (v == NULL) {
! 			PyErr_SetObject(PyExc_AttributeError, name);
  			return NULL;
  		}
--- 593,600 ----
  		v = class_lookup(inst->in_class, name, &class);
  		if (v == NULL) {
! 			PyErr_Format(PyExc_AttributeError,
! 				     "'%.50s' instance has no attribute '%.400s'",
! 				     PyString_AsString(inst->in_class->cl_name),
! 				     sname);
  			return NULL;
  		}