clearer error messages for apply() and "no locals"

This commit is contained in:
Jeremy Hylton 2001-01-19 03:25:05 +00:00
parent b4ed8c4db0
commit c862cf400f
2 changed files with 18 additions and 11 deletions

View File

@ -70,8 +70,9 @@ builtin_apply(PyObject *self, PyObject *args)
if (alist != NULL) { if (alist != NULL) {
if (!PyTuple_Check(alist)) { if (!PyTuple_Check(alist)) {
if (!PySequence_Check(alist)) { if (!PySequence_Check(alist)) {
PyErr_SetString(PyExc_TypeError, PyErr_Format(PyExc_TypeError,
"apply() arg 2 must be a sequence"); "apply() arg 2 expect sequence, found %s",
alist->ob_type->tp_name);
return NULL; return NULL;
} }
t = PySequence_Tuple(alist); t = PySequence_Tuple(alist);
@ -81,8 +82,9 @@ builtin_apply(PyObject *self, PyObject *args)
} }
} }
if (kwdict != NULL && !PyDict_Check(kwdict)) { if (kwdict != NULL && !PyDict_Check(kwdict)) {
PyErr_SetString(PyExc_TypeError, PyErr_Format(PyExc_TypeError,
"apply() arg 3 must be a dictionary"); "apply() arg 3 expected dictionary, found %s",
kwdict->ob_type->tp_name);
goto finally; goto finally;
} }
retval = PyEval_CallObjectWithKeywords(func, alist, kwdict); retval = PyEval_CallObjectWithKeywords(func, alist, kwdict);

View File

@ -20,6 +20,8 @@
#include <ctype.h> #include <ctype.h>
#define REPR(O) PyString_AS_STRING(PyObject_Repr(O))
/* Turn this on if your compiler chokes on the big switch: */ /* Turn this on if your compiler chokes on the big switch: */
/* #define CASE_TOO_BIG 1 */ /* #define CASE_TOO_BIG 1 */
@ -1438,8 +1440,9 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
w = GETNAMEV(oparg); w = GETNAMEV(oparg);
v = POP(); v = POP();
if ((x = f->f_locals) == NULL) { if ((x = f->f_locals) == NULL) {
PyErr_SetString(PyExc_SystemError, PyErr_Format(PyExc_SystemError,
"no locals"); "no locals found when storing %s",
REPR(w));
break; break;
} }
err = PyDict_SetItem(x, w, v); err = PyDict_SetItem(x, w, v);
@ -1449,8 +1452,9 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
case DELETE_NAME: case DELETE_NAME:
w = GETNAMEV(oparg); w = GETNAMEV(oparg);
if ((x = f->f_locals) == NULL) { if ((x = f->f_locals) == NULL) {
PyErr_SetString(PyExc_SystemError, PyErr_Format(PyExc_SystemError,
"no locals"); "no locals when deleting %s",
REPR(w));
break; break;
} }
if ((err = PyDict_DelItem(x, w)) != 0) if ((err = PyDict_DelItem(x, w)) != 0)
@ -1543,8 +1547,9 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
case LOAD_NAME: case LOAD_NAME:
w = GETNAMEV(oparg); w = GETNAMEV(oparg);
if ((x = f->f_locals) == NULL) { if ((x = f->f_locals) == NULL) {
PyErr_SetString(PyExc_SystemError, PyErr_Format(PyExc_SystemError,
"no locals"); "no locals when loading %s",
REPR(w));
break; break;
} }
x = PyDict_GetItem(x, w); x = PyDict_GetItem(x, w);
@ -1716,7 +1721,7 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
PyFrame_FastToLocals(f); PyFrame_FastToLocals(f);
if ((x = f->f_locals) == NULL) { if ((x = f->f_locals) == NULL) {
PyErr_SetString(PyExc_SystemError, PyErr_SetString(PyExc_SystemError,
"no locals"); "no locals found during 'import *'");
break; break;
} }
err = import_all_from(x, v); err = import_all_from(x, v);