[Python-checkins] python/dist/src/Python ceval.c,2.416,2.417
rhettinger at users.sourceforge.net
rhettinger at users.sourceforge.net
Thu Sep 16 18:42:03 CEST 2004
Update of /cvsroot/python/python/dist/src/Python
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7202
Modified Files:
ceval.c
Log Message:
SF bug #1014215: Unspecific errors with metaclass
High level error message was stomping useful detailed messages from lower
level routines.
The new approach is to augment string error messages returned by the low
level routines. The provides both high and low level information. If
the exception value is not a string, no changes are made.
To see the improved messages in action, type:
import random
class R(random): pass
class B(bool): pass
Index: ceval.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/ceval.c,v
retrieving revision 2.416
retrieving revision 2.417
diff -u -d -r2.416 -r2.417
--- ceval.c 29 Aug 2004 15:51:52 -0000 2.416
+++ ceval.c 16 Sep 2004 16:41:57 -0000 2.417
@@ -4086,10 +4086,22 @@
/* A type error here likely means that the user passed
in a base that was not a class (such the random module
instead of the random.random type). Help them out with
- a more informative error message */
- PyErr_SetString(PyExc_TypeError,
- "Error when calling the metaclass.\n" \
- "Make sure the base arguments are valid.");
+ by augmenting the error message with more information.*/
+
+ PyObject *ptype, *pvalue, *ptraceback;
+
+ PyErr_Fetch(&ptype, &pvalue, &ptraceback);
+ if (PyString_Check(pvalue)) {
+ PyObject *newmsg;
+ newmsg = PyString_FromFormat(
+ "Error when calling the metaclass bases\n %s",
+ PyString_AS_STRING(pvalue));
+ if (newmsg != NULL) {
+ Py_DECREF(pvalue);
+ pvalue = newmsg;
+ }
+ }
+ PyErr_Restore(ptype, pvalue, ptraceback);
}
return result;
}
More information about the Python-checkins
mailing list