diff options
author | Jeremy Hylton <jeremy@alum.mit.edu> | 2001-01-19 03:25:05 (GMT) |
---|---|---|
committer | Jeremy Hylton <jeremy@alum.mit.edu> | 2001-01-19 03:25:05 (GMT) |
commit | c862cf400f90e7ef63fa333d1af141934eb92c59 (patch) | |
tree | e82e932ade9c76290b811dde761022daf71e369a /Python | |
parent | b4ed8c4db0701dcce6c83fcdb82da1bdc651bf29 (diff) | |
download | cpython-c862cf400f90e7ef63fa333d1af141934eb92c59.zip cpython-c862cf400f90e7ef63fa333d1af141934eb92c59.tar.gz cpython-c862cf400f90e7ef63fa333d1af141934eb92c59.tar.bz2 |
clearer error messages for apply() and "no locals"
Diffstat (limited to 'Python')
-rw-r--r-- | Python/bltinmodule.c | 10 | ||||
-rw-r--r-- | Python/ceval.c | 19 |
2 files changed, 18 insertions, 11 deletions
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index ca9f312..66372da 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -70,8 +70,9 @@ builtin_apply(PyObject *self, PyObject *args) if (alist != NULL) { if (!PyTuple_Check(alist)) { if (!PySequence_Check(alist)) { - PyErr_SetString(PyExc_TypeError, - "apply() arg 2 must be a sequence"); + PyErr_Format(PyExc_TypeError, + "apply() arg 2 expect sequence, found %s", + alist->ob_type->tp_name); return NULL; } t = PySequence_Tuple(alist); @@ -81,8 +82,9 @@ builtin_apply(PyObject *self, PyObject *args) } } if (kwdict != NULL && !PyDict_Check(kwdict)) { - PyErr_SetString(PyExc_TypeError, - "apply() arg 3 must be a dictionary"); + PyErr_Format(PyExc_TypeError, + "apply() arg 3 expected dictionary, found %s", + kwdict->ob_type->tp_name); goto finally; } retval = PyEval_CallObjectWithKeywords(func, alist, kwdict); diff --git a/Python/ceval.c b/Python/ceval.c index c01e16d..199272c 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -20,6 +20,8 @@ #include <ctype.h> +#define REPR(O) PyString_AS_STRING(PyObject_Repr(O)) + /* Turn this on if your compiler chokes on the big switch: */ /* #define CASE_TOO_BIG 1 */ @@ -1438,8 +1440,9 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals, w = GETNAMEV(oparg); v = POP(); if ((x = f->f_locals) == NULL) { - PyErr_SetString(PyExc_SystemError, - "no locals"); + PyErr_Format(PyExc_SystemError, + "no locals found when storing %s", + REPR(w)); break; } err = PyDict_SetItem(x, w, v); @@ -1449,8 +1452,9 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals, case DELETE_NAME: w = GETNAMEV(oparg); if ((x = f->f_locals) == NULL) { - PyErr_SetString(PyExc_SystemError, - "no locals"); + PyErr_Format(PyExc_SystemError, + "no locals when deleting %s", + REPR(w)); break; } if ((err = PyDict_DelItem(x, w)) != 0) @@ -1543,8 +1547,9 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals, case LOAD_NAME: w = GETNAMEV(oparg); if ((x = f->f_locals) == NULL) { - PyErr_SetString(PyExc_SystemError, - "no locals"); + PyErr_Format(PyExc_SystemError, + "no locals when loading %s", + REPR(w)); break; } x = PyDict_GetItem(x, w); @@ -1716,7 +1721,7 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals, PyFrame_FastToLocals(f); if ((x = f->f_locals) == NULL) { PyErr_SetString(PyExc_SystemError, - "no locals"); + "no locals found during 'import *'"); break; } err = import_all_from(x, v); |