*** /home/skip/tmp/object.c.~2.166~ Wed Mar 20 12:30:42 2002 --- /home/skip/tmp/object.c Wed Mar 20 12:30:42 2002 *************** *** 1080,1085 **** --- 1080,1116 ---- return res; } + static void + format_no_attribute_error(PyObject *o, PyObject *name) + { + static int recurse = 0; + PyTypeObject *tp = o->ob_type; + + if (!recurse) { + recurse = 1; + if (PyObject_HasAttrString(o, "__name__")) { + PyObject *oname; + oname = PyObject_GetAttrString(o, "__name__"); + if (oname != NULL && PyString_Check(oname)) { + PyErr_Format(PyExc_AttributeError, + "%.50s object '%.50s' has no" + " attribute '%.400s'", + tp->tp_name, + PyString_AS_STRING(oname), + PyString_AS_STRING(name)); + Py_DECREF(oname); + recurse = 0; + return; + } + } + recurse = 0; + /* fall thru to default attribute error msg format */ + } + PyErr_Format(PyExc_AttributeError, + "%.50s object has no attribute '%.400s'", + tp->tp_name, PyString_AS_STRING(name)); + } + PyObject * PyObject_GetAttr(PyObject *v, PyObject *name) { *************** *** 1107,1115 **** return (*tp->tp_getattro)(v, name); if (tp->tp_getattr != NULL) return (*tp->tp_getattr)(v, PyString_AS_STRING(name)); ! PyErr_Format(PyExc_AttributeError, ! "'%.50s' object has no attribute '%.400s'", ! tp->tp_name, PyString_AS_STRING(name)); return NULL; } --- 1138,1144 ---- return (*tp->tp_getattro)(v, name); if (tp->tp_getattr != NULL) return (*tp->tp_getattr)(v, PyString_AS_STRING(name)); ! format_no_attribute_error(v, name); return NULL; } *************** *** 1280,1288 **** goto done; } ! PyErr_Format(PyExc_AttributeError, ! "'%.50s' object has no attribute '%.400s'", ! tp->tp_name, PyString_AS_STRING(name)); done: Py_DECREF(name); return res; --- 1309,1315 ---- goto done; } ! format_no_attribute_error(obj, name); done: Py_DECREF(name); return res; *************** *** 1359,1367 **** } if (descr == NULL) { ! PyErr_Format(PyExc_AttributeError, ! "'%.50s' object has no attribute '%.400s'", ! tp->tp_name, PyString_AS_STRING(name)); goto done; } --- 1386,1392 ---- } if (descr == NULL) { ! format_no_attribute_error(obj, name); goto done; }