Changes to error messages to increase consistency & clarity.
This (mostly) closes SourceForge patch #101839.
(1, 2, 3) {'b': 5, 'a': 4}
(1, 2, 3, 4, 5) {'b': 7, 'a': 6}
(1, 2, 3, 6, 7) {'y': 5, 'b': 9, 'x': 4, 'a': 8}
-TypeError: not enough arguments; expected 1, got 0
-TypeError: not enough arguments; expected 1, got 0
-TypeError: not enough arguments; expected 1, got 0
+TypeError: not enough arguments to g(); expected 1, got 0
+TypeError: not enough arguments to g(); expected 1, got 0
+TypeError: not enough arguments to g(); expected 1, got 0
1 () {}
1 (2,) {}
1 (2, 3) {}
1 () {'d': 4, 'b': 2, 'c': 3, 'a': 1}
{'b': 2, 'c': 3, 'a': 1}
{'b': 2, 'c': 3, 'a': 1}
-keyword parameter redefined: x
-keyword parameter redefined: b
+keyword parameter 'x' redefined in call to g()
+keyword parameter 'b' redefined in function call
keywords must be strings
-unexpected keyword argument: e
+h() got an unexpected keyword argument 'e'
* argument must be a sequence
** argument must be a dictionary
3 512 1
if ( dbm_store(dp->di_dbm, krec, drec, DBM_REPLACE) < 0 ) {
dbm_clearerr(dp->di_dbm);
PyErr_SetString(DbmError,
- "Cannot add item to database");
+ "cannot add item to database");
return -1;
}
}
val.dsize = PyString_GET_SIZE(defvalue);
if (dbm_store(dp->di_dbm, key, val, DBM_INSERT) < 0) {
dbm_clearerr(dp->di_dbm);
- PyErr_SetString(DbmError, "Cannot add item to database");
+ PyErr_SetString(DbmError, "cannot add item to database");
return NULL;
}
return defvalue;
iflags = O_RDWR|O_CREAT|O_TRUNC;
else {
PyErr_SetString(DbmError,
- "Flags should be one of 'r', 'w', 'c' or 'n'");
+ "arg 2 to open should be 'r', 'w', 'c', or 'n'");
return NULL;
}
return newdbmobject(name, iflags, mode);
if (n != 0)
res = parser_newastobject(n, type);
else
- err_string("Could not parse string.");
+ err_string("could not parse string");
}
return (res);
}
else {
/* This is a fragment, at best. */
PyNode_Free(tree);
- err_string("Parse tree does not use a valid start symbol.");
+ err_string("parse tree does not use a valid start symbol");
}
}
/* Make sure we throw an exception on all errors. We should never
* get this, but we'd do well to be sure something is done.
*/
if ((ast == 0) && !PyErr_Occurred())
- err_string("Unspecified ast error occurred.");
+ err_string("unspecified AST error occurred");
return (ast);
}
PyObject *temp;
if ((len != 2) && (len != 3)) {
- err_string("Terminal nodes must have 2 or 3 entries.");
+ err_string("terminal nodes must have 2 or 3 entries");
return 0;
}
temp = PySequence_GetItem(elem, 1);
return 0;
if (!PyString_Check(temp)) {
PyErr_Format(parser_error,
- "Second item in terminal node must be a string,"
- " found %s.",
+ "second item in terminal node must be a string,"
+ " found %s",
((PyTypeObject*)PyObject_Type(temp))->tp_name);
Py_DECREF(temp);
return 0;
*line_num = PyInt_AS_LONG(o);
else {
PyErr_Format(parser_error,
- "Third item in terminal node must be an"
- " integer, found %s.",
+ "third item in terminal node must be an"
+ " integer, found %s",
((PyTypeObject*)PyObject_Type(temp))->tp_name);
Py_DECREF(o);
Py_DECREF(temp);
* Throw an exception.
*/
PyErr_SetObject(parser_error,
- Py_BuildValue("os", elem, "Unknown node type."));
+ Py_BuildValue("os", elem, "unknown node type."));
Py_XDECREF(elem);
return (0);
}
&& validate_name(CHILD(tree, 2), NULL));
else {
res = 0;
- err_string("Illegal number of children for dotted_as_name.");
+ err_string("illegal number of children for dotted_as_name");
}
}
return res;
&& validate_expr(CHILD(tree, 1)));
if (!res && !PyErr_Occurred())
- err_string("Illegal exec statement.");
+ err_string("illegal exec statement");
if (res && (nch > 2))
res = (validate_name(CHILD(tree, 2), "in")
&& validate_test(CHILD(tree, 3)));
&& validate_test(CHILD(tree, 1)));
if (!res && !PyErr_Occurred())
- err_string("Illegal assert statement.");
+ err_string("illegal assert statement");
if (res && (nch > 2))
res = (validate_comma(CHILD(tree, 2))
&& validate_test(CHILD(tree, 3)));
res = ((strcmp(STR(CHILD(tree, pos)), "except") == 0)
|| (strcmp(STR(CHILD(tree, pos)), "else") == 0));
if (!res)
- err_string("Illegal trailing triple in try statement.");
+ err_string("illegal trailing triple in try statement");
}
else if (nch == (pos + 6)) {
res = (validate_name(CHILD(tree, pos), "except")
|| (strcmp(STR(tree), "is") == 0));
if (!res) {
PyErr_Format(parser_error,
- "Illegal operator: '%s'.", STR(tree));
+ "illegal operator '%s'", STR(tree));
}
break;
default:
- err_string("Illegal comparison operator type.");
+ err_string("illegal comparison operator type");
break;
}
}
|| ((strcmp(STR(CHILD(tree, 0)), "not") == 0)
&& (strcmp(STR(CHILD(tree, 1)), "in") == 0))));
if (!res && !PyErr_Occurred())
- err_string("Unknown comparison operator.");
+ err_string("unknown comparison operator");
}
return (res);
}
res = validate_trailer(CHILD(tree, pos++));
if (res && (pos < nch)) {
if (!is_even(nch - pos)) {
- err_string("Illegal number of nodes for 'power'.");
+ err_string("illegal number of nodes for 'power'");
return (0);
}
for ( ; res && (pos < (nch - 1)); pos += 2)
if (res)
next = CHILD(tree, 0);
else if (nch == 1)
- err_string("Illegal flow_stmt type.");
+ err_string("illegal flow_stmt type");
break;
/*
* Compound statements.
default:
/* Hopefully never reached! */
- err_string("Unrecogniged node type.");
+ err_string("unrecognized node type");
res = 0;
break;
}
int res = validate_eval_input(tree);
if (!res && !PyErr_Occurred())
- err_string("Could not validate expression tuple.");
+ err_string("could not validate expression tuple");
return (res);
}
* this, we have some debugging to do.
*/
if (!res && !PyErr_Occurred())
- err_string("VALIDATION FAILURE: report this to the maintainer!.");
+ err_string("VALIDATION FAILURE: report this to the maintainer!");
return (res);
}
}
else if (!PyArg_Parse(arg, "(ll)", &atime, &mtime)) {
PyErr_SetString(PyExc_TypeError,
- "Second argument must be a 2-tuple of numbers.");
+ "utime() arg 2 must be a tuple (atime, mtime)");
return NULL;
}
else {
getitem = PyTuple_GetItem;
}
else {
- PyErr_SetString(PyExc_TypeError, "argv must be tuple or list");
+ PyErr_SetString(PyExc_TypeError, "execv() arg 2 must be a tuple or list");
return NULL;
}
if (argc == 0) {
- PyErr_SetString(PyExc_ValueError, "empty argument list");
+ PyErr_SetString(PyExc_ValueError, "execv() arg 2 must not be empty");
return NULL;
}
if (!PyArg_Parse((*getitem)(argv, i), "s", &argvlist[i])) {
PyMem_DEL(argvlist);
PyErr_SetString(PyExc_TypeError,
- "all arguments must be strings");
+ "execv() arg 2 must contain only strings");
return NULL;
}
getitem = PyTuple_GetItem;
}
else {
- PyErr_SetString(PyExc_TypeError, "argv must be tuple or list");
+ PyErr_SetString(PyExc_TypeError, "execve() arg 2 must be a tuple or list");
return NULL;
}
if (!PyMapping_Check(env)) {
- PyErr_SetString(PyExc_TypeError, "env must be mapping object");
+ PyErr_SetString(PyExc_TypeError, "execve() arg 3 must be a mapping object");
return NULL;
}
if (argc == 0) {
PyErr_SetString(PyExc_ValueError,
- "empty argument list");
+ "execve() arg 2 must not be empty");
return NULL;
}
}
for (i = 0; i < argc; i++) {
if (!PyArg_Parse((*getitem)(argv, i),
- "s;argv must be list of strings",
+ "s;execve() arg 2 must contain only strings",
&argvlist[i]))
{
goto fail_1;
if (!key || !val)
goto fail_2;
- if (!PyArg_Parse(key, "s;non-string key in env", &k) ||
- !PyArg_Parse(val, "s;non-string value in env", &v))
+ if (!PyArg_Parse(key, "s;execve() arg 3 contains a non-string key", &k) ||
+ !PyArg_Parse(val, "s;execve() arg 3 contains a non-string value", &v))
{
goto fail_2;
}
getitem = PyTuple_GetItem;
}
else {
- PyErr_SetString(PyExc_TypeError, "argv must be tuple or list");
+ PyErr_SetString(PyExc_TypeError, "spawmv() arg 2 must be a tuple or list");
return NULL;
}
if (!PyArg_Parse((*getitem)(argv, i), "s", &argvlist[i])) {
PyMem_DEL(argvlist);
PyErr_SetString(PyExc_TypeError,
- "all arguments must be strings");
+ "spawnv() arg 2 must contain only strings");
return NULL;
}
}
getitem = PyTuple_GetItem;
}
else {
- PyErr_SetString(PyExc_TypeError, "argv must be tuple or list");
+ PyErr_SetString(PyExc_TypeError, "spawnve() arg 2 must be a tuple or list");
return NULL;
}
if (!PyMapping_Check(env)) {
- PyErr_SetString(PyExc_TypeError, "env must be mapping object");
+ PyErr_SetString(PyExc_TypeError, "spawnve() arg 3 must be a mapping object");
return NULL;
}
}
for (i = 0; i < argc; i++) {
if (!PyArg_Parse((*getitem)(argv, i),
- "s;argv must be list of strings",
+ "s;spawnve() arg 2 must contain only strings",
&argvlist[i]))
{
goto fail_1;
if (!key || !val)
goto fail_2;
- if (!PyArg_Parse(key, "s;non-string key in env", &k) ||
- !PyArg_Parse(val, "s;non-string value in env", &v))
+ if (!PyArg_Parse(key, "s;spawnve() arg 3 contains a non-string key", &k) ||
+ !PyArg_Parse(val, "s;spawnve() arg 3 contains a non-string value", &v))
{
goto fail_2;
}
if (*mode == 'r')
tm = _O_RDONLY;
else if (*mode != 'w') {
- PyErr_SetString(PyExc_ValueError, "mode must be 'r' or 'w'");
+ PyErr_SetString(PyExc_ValueError, "popen() arg 2 must be 'r' or 'w'");
return NULL;
} else
tm = _O_WRONLY;
if (bufsize != -1) {
- PyErr_SetString(PyExc_ValueError, "bufsize must be -1");
+ PyErr_SetString(PyExc_ValueError, "popen() arg 3 must be -1");
return NULL;
}
if (*mode == 't')
tm = _O_TEXT;
else if (*mode != 'b') {
- PyErr_SetString(PyExc_ValueError, "mode must be 't' or 'b'");
+ PyErr_SetString(PyExc_ValueError, "popen2() arg 2 must be 't' or 'b'");
return NULL;
} else
tm = _O_BINARY;
if (bufsize != -1) {
- PyErr_SetString(PyExc_ValueError, "bufsize must be -1");
+ PyErr_SetString(PyExc_ValueError, "popen2() arg 3 must be -1");
return NULL;
}
if (*mode == 't')
tm = _O_TEXT;
else if (*mode != 'b') {
- PyErr_SetString(PyExc_ValueError, "mode must be 't' or 'b'");
+ PyErr_SetString(PyExc_ValueError, "popen3() arg 2 must be 't' or 'b'");
return NULL;
} else
tm = _O_BINARY;
if (bufsize != -1) {
- PyErr_SetString(PyExc_ValueError, "bufsize must be -1");
+ PyErr_SetString(PyExc_ValueError, "popen3() arg 3 must be -1");
return NULL;
}
if (*mode == 't')
tm = _O_TEXT;
else if (*mode != 'b') {
- PyErr_SetString(PyExc_ValueError, "mode must be 't' or 'b'");
+ PyErr_SetString(PyExc_ValueError, "popen4() arg 2 must be 't' or 'b'");
return NULL;
} else
tm = _O_BINARY;
if (bufsize != -1) {
- PyErr_SetString(PyExc_ValueError, "bufsize must be -1");
+ PyErr_SetString(PyExc_ValueError, "popen4() arg 3 must be -1");
return NULL;
}
* an exception. Just die.
*/
Py_FatalError("unable to allocate interpreter state "
- "when closing popen object.");
+ "when closing popen object");
return -1; /* unreachable */
}
pThreadState = PyThreadState_New(pInterpreterState);
if (!pThreadState) {
Py_FatalError("unable to allocate thread state "
- "when closing popen object.");
+ "when closing popen object");
return -1; /* unreachable */
}
/* Grab the global lock. Note that this will deadlock if the
message = strerror(code);
if (message == NULL) {
PyErr_SetString(PyExc_ValueError,
- "strerror code out of range");
+ "strerror() argument out of range");
return NULL;
}
return PyString_FromString(message);
}
v = class_lookup(op, name, &class);
if (v == NULL) {
- PyErr_SetObject(PyExc_AttributeError, name);
+ PyErr_Format(PyExc_AttributeError,
+ "class %.50s has no attribute '%.400s'",
+ PyString_AS_STRING(op->cl_name), sname);
return NULL;
}
Py_INCREF(v);
if (v == NULL) {
int rv = PyDict_DelItem(op->cl_dict, name);
if (rv < 0)
- PyErr_SetString(PyExc_AttributeError,
- "delete non-existing class attribute");
+ PyErr_Format(PyExc_AttributeError,
+ "class %.50s has no attribute '%.400s'",
+ PyString_AS_STRING(op->cl_name), sname);
return rv;
}
else
}
v = instance_getattr2(inst, name);
if (v == NULL) {
- PyErr_Format(PyExc_AttributeError,"'%.50s' instance has no attribute '%.400s'",
+ PyErr_Format(PyExc_AttributeError,
+ "%.50s instance has no attribute '%.400s'",
PyString_AS_STRING(inst->in_class->cl_name), sname);
}
return v;
if (v == NULL) {
int rv = PyDict_DelItem(inst->in_dict, name);
if (rv < 0)
- PyErr_SetString(PyExc_AttributeError,
- "delete non-existing instance attribute");
+ PyErr_Format(PyExc_AttributeError,
+ "%.50s instance has no attribute '%.400s'",
+ PyString_AS_STRING(inst->in_class->cl_name),
+ PyString_AS_STRING(name));
return rv;
}
else
buffersize *= 2;
if (buffersize > INT_MAX) {
PyErr_SetString(PyExc_OverflowError,
- "line is too long for a Python string");
+ "line is longer than a Python string can hold");
goto error;
}
if (big_buffer == NULL) {
return err_closed();
if (args == NULL || !PySequence_Check(args)) {
PyErr_SetString(PyExc_TypeError,
- "writelines() requires sequence of strings");
+ "writelines() argument must be a sequence of strings");
return NULL;
}
islist = PyList_Check(args);
&buffer,
&len))) {
PyErr_SetString(PyExc_TypeError,
- "writelines() requires sequences of strings");
+ "writelines() argument must be a sequence of strings");
goto error;
}
line = PyString_FromStringAndSize(buffer,
if (iv == 0.0) {
if (iw < 0.0) {
PyErr_SetString(PyExc_ZeroDivisionError,
- "0.0 to a negative power");
+ "0.0 cannot be raised to a negative power");
return NULL;
}
return PyFloat_FromDouble(0.0);
/* Sort out special cases here instead of relying on pow() */
if (iv < 0.0) {
PyErr_SetString(PyExc_ValueError,
- "negative number to a float power");
+ "negative number cannot be raised to a fractional power");
return NULL;
}
errno = 0;
char buffer[256]; /* For errors */
if ((base != 0 && base < 2) || base > 36) {
- PyErr_SetString(PyExc_ValueError, "invalid base for int()");
+ PyErr_SetString(PyExc_ValueError, "int() base must be >= 2 and <= 36");
return NULL;
}
if (yi == 0) {
PyErr_SetString(PyExc_ZeroDivisionError,
- "integer division or modulo");
+ "integer division or modulo by zero");
return -1;
}
if (yi < 0) {
if (iw < 0) {
if (iv)
PyErr_SetString(PyExc_ValueError,
- "integer to a negative power");
+ "cannot raise integer to a negative power");
else
PyErr_SetString(PyExc_ZeroDivisionError,
- "0 to a negative power");
+ "cannot raise 0 to a negative power");
return NULL;
}
if ((PyObject *)z != Py_None) {
iz = z->ob_ival;
if (iz == 0) {
PyErr_SetString(PyExc_ValueError,
- "pow(x, y, z) with z==0");
+ "pow() arg 3 cannot be 0");
return NULL;
}
}
overflow:
PyErr_SetString(PyExc_OverflowError,
- "long int too long to convert");
+ "long int too large to convert");
return -1;
}
x = (x << SHIFT) + v->ob_digit[i];
if ((x >> SHIFT) != prev) {
PyErr_SetString(PyExc_OverflowError,
- "long int too long to convert");
+ "long int too large to convert");
return (unsigned long) -1;
}
}
if ((base != 0 && base < 2) || base > 36) {
PyErr_SetString(PyExc_ValueError,
- "invalid base for long literal");
+ "long() arg 2 must be >= 2 and <= 36");
return NULL;
}
while (*str != '\0' && isspace(Py_CHARMASK(*str)))
if (size_b == 0) {
PyErr_SetString(PyExc_ZeroDivisionError,
- "long division or modulo");
+ "long division or modulo by zero");
return -1;
}
if (size_a < size_b ||
module_getattr(PyModuleObject *m, char *name)
{
PyObject *res;
+ char* modname;
if (strcmp(name, "__dict__") == 0) {
Py_INCREF(m->md_dict);
return m->md_dict;
}
res = PyDict_GetItemString(m->md_dict, name);
- if (res == NULL)
- PyErr_SetString(PyExc_AttributeError, name);
+ if (res == NULL) {
+ modname = PyModule_GetName((PyObject *)m);
+ if (modname == NULL) {
+ PyErr_Clear();
+ modname = "?";
+ }
+ PyErr_Format(PyExc_AttributeError,
+ "'%.50s' module has no attribute '%.400s'",
+ modname, name);
+ }
else
Py_INCREF(res);
return res;
static int
module_setattr(PyModuleObject *m, char *name, PyObject *v)
{
+ char* modname;
if (name[0] == '_' && strcmp(name, "__dict__") == 0) {
PyErr_SetString(PyExc_TypeError,
"read-only special attribute");
}
if (v == NULL) {
int rv = PyDict_DelItemString(m->md_dict, name);
- if (rv < 0)
- PyErr_SetString(PyExc_AttributeError,
- "delete non-existing module attribute");
+ if (rv < 0) {
+ modname = PyModule_GetName((PyObject *)m);
+ if (modname == NULL) {
+ PyErr_Clear();
+ modname = "?";
+ }
+ PyErr_Format(PyExc_AttributeError,
+ "'%.50s' module has no attribute '%.400s'",
+ modname, name);
+ }
return rv;
}
else
return -1;
#ifdef USE_STACKCHECK
if (PyOS_CheckStack()) {
- PyErr_SetString(PyExc_MemoryError, "Stack overflow");
+ PyErr_SetString(PyExc_MemoryError, "stack overflow");
return -1;
}
#endif
return NULL;
#ifdef USE_STACKCHECK
if (PyOS_CheckStack()) {
- PyErr_SetString(PyExc_MemoryError, "Stack overflow");
+ PyErr_SetString(PyExc_MemoryError, "stack overflow");
return NULL;
}
#endif
always given), therefore increase by one to 10+prec. */
if (buflen <= (size_t)10 + (size_t)prec) {
PyErr_SetString(PyExc_OverflowError,
- "formatted float is too long (precision too long?)");
+ "formatted float is too long (precision too large?)");
return -1;
}
sprintf(buf, fmt, x);
worst case buf = '0x' + [0-9]*prec, where prec >= 11 */
if (buflen <= 13 || buflen <= (size_t)2 + (size_t)prec) {
PyErr_SetString(PyExc_OverflowError,
- "formatted integer is too long (precision too long?)");
+ "formatted integer is too long (precision too large?)");
return -1;
}
sprintf(buf, fmt, x);
if (!PyTuple_Check(alist)) {
if (!PySequence_Check(alist)) {
PyErr_SetString(PyExc_TypeError,
- "apply() 2nd argument must be a sequence");
+ "apply() arg 2 must be a sequence");
return NULL;
}
t = PySequence_Tuple(alist);
}
if (kwdict != NULL && !PyDict_Check(kwdict)) {
PyErr_SetString(PyExc_TypeError,
- "apply() 3rd argument must be dictionary");
+ "apply() arg 3 must be a dictionary");
goto finally;
}
retval = PyEval_CallObjectWithKeywords(func, alist, kwdict);
sqf = seq->ob_type->tp_as_sequence;
if (sqf == NULL || sqf->sq_length == NULL || sqf->sq_item == NULL) {
PyErr_SetString(PyExc_TypeError,
- "argument 2 to filter() must be a sequence type");
+ "filter() arg 2 must be a sequence");
goto Fail_2;
}
start = Py_single_input;
else {
PyErr_SetString(PyExc_ValueError,
- "compile() mode must be 'exec' or 'eval' or 'single'");
+ "compile() arg 3 must be 'exec' or 'eval' or 'single'");
return NULL;
}
return Py_CompileString(str, filename, start);
}
else if (PyObject_AsCharBuffer(v, &s, &len)) {
PyErr_SetString(PyExc_TypeError,
- "complex() needs a string first argument");
+ "complex() arg is not a string");
return NULL;
}
s++;
if (s[0] == '\0') {
PyErr_SetString(PyExc_ValueError,
- "empty string for complex()");
+ "complex() arg is an empty string");
return NULL;
}
if (s-start != len) {
PyErr_SetString(
PyExc_ValueError,
- "null byte in argument for complex()");
+ "complex() arg contains a null byte");
return NULL;
}
if(!done) sw_error=1;
if (sw_error) {
PyErr_SetString(PyExc_ValueError,
- "malformed string for complex()");
+ "complex() arg is a malformed string");
return NULL;
}
((nbi = i->ob_type->tp_as_number) == NULL ||
nbi->nb_float == NULL))) {
PyErr_SetString(PyExc_TypeError,
- "complex() argument can't be converted to complex");
+ "complex() arg can't be converted to complex");
return NULL;
}
/* XXX Hack to support classes with __complex__ method */
if (!PyString_Check(cmd) &&
!PyUnicode_Check(cmd)) {
PyErr_SetString(PyExc_TypeError,
- "eval() argument 1 must be string or code object");
+ "eval() arg 1 must be a string or code object");
return NULL;
}
if (PyString_AsStringAndSize(cmd, &str, NULL))
base);
else {
PyErr_SetString(PyExc_TypeError,
- "can't convert non-string with explicit base");
+ "int() can't convert non-string with explicit base");
return NULL;
}
}
base);
else {
PyErr_SetString(PyExc_TypeError,
- "can't convert non-string with explicit base");
+ "long() can't convert non-string with explicit base");
return NULL;
}
}
sq = v->ob_type->tp_as_sequence;
if (sq == NULL || sq->sq_item == NULL) {
PyErr_SetString(PyExc_TypeError,
- "min() or max() of non-sequence");
+ "min() or max() arg must be a sequence");
return NULL;
}
w = NULL;
}
if (w == NULL)
PyErr_SetString(PyExc_ValueError,
- "min() or max() of empty sequence");
+ "min() or max() arg is an empty sequence");
return w;
}
ord = (long)*PyUnicode_AS_UNICODE(obj);
} else {
PyErr_Format(PyExc_TypeError,
- "expected string or Unicode character, " \
+ "ord() expected string or Unicode character, " \
"%.200s found", obj->ob_type->tp_name);
return NULL;
}
return PyInt_FromLong(ord);
PyErr_Format(PyExc_TypeError,
- "expected a character, length-%d string found",
+ "ord() expected a character, length-%d string found",
size);
return NULL;
}
return NULL;
}
if (istep == 0) {
- PyErr_SetString(PyExc_ValueError, "zero step for range()");
+ PyErr_SetString(PyExc_ValueError, "range() arg 3 must not be zero");
return NULL;
}
if (istep > 0)
n = (int)bign;
if (bign < 0 || (long)n != bign) {
PyErr_SetString(PyExc_OverflowError,
- "range() has too many items");
+ "range() result has too many items");
return NULL;
}
v = PyList_New(n);
return NULL;
}
if (istep == 0) {
- PyErr_SetString(PyExc_ValueError, "zero step for xrange()");
+ PyErr_SetString(PyExc_ValueError, "xrange() arg 3 must not be zero");
return NULL;
}
if (istep > 0)
n = get_len_of_range(ihigh, ilow, -istep);
if (n < 0) {
PyErr_SetString(PyExc_OverflowError,
- "xrange() has more than sys.maxint items");
+ "xrange() result has too many items");
return NULL;
}
return PyRange_New(ilow, n, istep, 1);
sqf = seq->ob_type->tp_as_sequence;
if (sqf == NULL || sqf->sq_item == NULL) {
PyErr_SetString(PyExc_TypeError,
- "2nd argument to reduce() must be a sequence object");
+ "reduce() arg 2 must be a sequence");
return NULL;
}
if (result == NULL)
PyErr_SetString(PyExc_TypeError,
- "reduce of empty sequence with no initial value");
+ "reduce() of empty sequence with no initial value");
return result;
if (icls != NULL) {
retval = abstract_issubclass(
icls, cls,
- "second argument must be a class",
+ "isinstance() arg 2 must be a class",
1);
Py_DECREF(icls);
if (retval < 0)
}
else {
PyErr_SetString(PyExc_TypeError,
- "second argument must be a class");
+ "isinstance() arg 2 must be a class");
return NULL;
}
}
else {
PyErr_SetString(PyExc_TypeError,
- "second argument must be a class");
+ "isinstance() arg 2 must be a class");
return NULL;
}
return PyInt_FromLong(retval);
if (itemsize < 1) {
PyErr_SetString(PyExc_TypeError,
- "at least one sequence is required");
+ "zip() requires at least one sequence");
return NULL;
}
/* args must be a tuple */
static void format_exc_check_arg(PyObject *, char *, PyObject *);
#define NAME_ERROR_MSG \
- "There is no variable named '%s'"
+ "name '%.200s' is not defined"
#define UNBOUNDLOCAL_ERROR_MSG \
- "Local variable '%.200s' referenced before assignment"
+ "local variable '%.200s' referenced before assignment"
/* Dynamic execution profile */
#ifdef DYNAMIC_EXECUTION_PROFILE
if (argcount > co->co_argcount) {
if (!(co->co_flags & CO_VARARGS)) {
PyErr_Format(PyExc_TypeError,
- "too many arguments; expected %d, got %d",
- co->co_argcount, argcount);
+ "too many arguments to %s(); "
+ "expected %d, got %d",
+ PyString_AsString(co->co_name),
+ co->co_argcount, argcount);
goto fail;
}
n = co->co_argcount;
if (j >= co->co_argcount) {
if (kwdict == NULL) {
PyErr_Format(PyExc_TypeError,
- "unexpected keyword argument: %.400s",
+ "%.200s() got an unexpected "
+ "keyword argument '%.400s'",
+ PyString_AsString(co->co_name),
PyString_AsString(keyword));
goto fail;
}
else {
if (GETLOCAL(j) != NULL) {
PyErr_Format(PyExc_TypeError,
- "keyword parameter redefined: %.400s",
- PyString_AsString(keyword));
+ "keyword parameter '%.400s' "
+ "redefined in call to %.200s()",
+ PyString_AsString(keyword),
+ PyString_AsString(co->co_name));
goto fail;
}
Py_INCREF(value);
for (i = argcount; i < m; i++) {
if (GETLOCAL(i) == NULL) {
PyErr_Format(PyExc_TypeError,
- "not enough arguments; expected %d, got %d",
- m, i);
+ "not enough arguments to "
+ "%.200s(); expected %d, got %d",
+ PyString_AsString(co->co_name),
+ m, i);
goto fail;
}
}
}
else {
if (argcount > 0 || kwcount > 0) {
- PyErr_SetString(PyExc_TypeError,
- "no arguments expected");
+ PyErr_Format(PyExc_TypeError,
+ "%.200s() expected no arguments",
+ PyString_AsString(co->co_name));
goto fail;
}
}
if (++tstate->recursion_depth > recursion_limit) {
--tstate->recursion_depth;
PyErr_SetString(PyExc_RuntimeError,
- "Maximum recursion depth exceeded");
+ "maximum recursion depth exceeded");
tstate->frame = f->f_back;
Py_DECREF(f);
return NULL;
/* Handy-dandy */ ;
else {
PyErr_SetString(PyExc_TypeError,
- "unbound method must be called with class instance 1st argument");
+ "unbound method must be called with instance as first argument");
x = NULL;
break;
}
PyObject *key = POP();
if (PyDict_GetItem(kwdict, key) != NULL) {
err = 1;
- PyErr_Format(PyExc_TypeError,
- "keyword parameter redefined: %.400s",
- PyString_AsString(key));
+ PyErr_Format(PyExc_TypeError,
+ "keyword parameter '%.400s' "
+ "redefined in function call",
+ PyString_AsString(key));
Py_DECREF(key);
Py_DECREF(value);
goto extcall_fail;
}
else if (tb != NULL && !PyTraceBack_Check(tb)) {
PyErr_SetString(PyExc_TypeError,
- "raise 3rd arg must be traceback or None");
+ "raise: arg 3 must be a traceback or None");
goto raise_error;
}
call_builtin(PyObject *func, PyObject *arg, PyObject *kw)
{
if (PyCFunction_Check(func)) {
+ PyCFunctionObject* f = (PyCFunctionObject*) func;
PyCFunction meth = PyCFunction_GetFunction(func);
PyObject *self = PyCFunction_GetSelf(func);
int flags = PyCFunction_GetFlags(func);
if (flags & METH_KEYWORDS)
return (*(PyCFunctionWithKeywords)meth)(self, arg, kw);
if (kw != NULL && PyDict_Size(kw) != 0) {
- PyErr_SetString(PyExc_TypeError,
- "this function takes no keyword arguments");
+ PyErr_Format(PyExc_TypeError,
+ "%.200s() takes no keyword arguments",
+ f->m_ml->ml_name);
return NULL;
}
return (*meth)(self, arg);
return PyInstance_New(func, arg, kw);
}
if (PyInstance_Check(func)) {
- PyObject *res, *call = PyObject_GetAttrString(func,"__call__");
+ PyObject *res, *call = PyObject_GetAttrString(func, "__call__");
if (call == NULL) {
+ PyInstanceObject *inst = (PyInstanceObject*) func;
PyErr_Clear();
- PyErr_SetString(PyExc_AttributeError,
- "no __call__ method defined");
+ PyErr_Format(PyExc_AttributeError,
+ "%.200s instance has no __call__ method",
+ PyString_AsString(inst->in_class->cl_name));
return NULL;
}
res = PyEval_CallObjectWithKeywords(call, arg, kw);
}
if (self == NULL) {
PyErr_SetString(PyExc_TypeError,
- "unbound method must be called with class instance 1st argument");
+ "unbound method must be called with instance as first argument");
return NULL;
}
Py_INCREF(arg);
}
} else {
PyErr_SetString(PyExc_TypeError,
- "slice index must be int");
+ "slice indices must be integers");
return 0;
}
/* Truncate -- very long indices are truncated anyway */
PyObject *w, *x;
if (!PyModule_Check(v)) {
PyErr_SetString(PyExc_TypeError,
- "import-from requires module object");
+ "import-from requires a module object");
return NULL;
}
w = PyModule_GetDict(v); /* TDB: can this not fail ? */
if (!PyModule_Check(v)) {
PyErr_SetString(PyExc_TypeError,
- "import-from requires module object");
+ "import-from requires a module object");
return -1;
}
w = PyModule_GetDict(v); /* TBD: can this not fail ? */
!PyCode_Check(prog) &&
!PyFile_Check(prog)) {
PyErr_SetString(PyExc_TypeError,
- "exec 1st arg must be string, code or file object");
+ "exec: arg 1 must be a string, file, or code object");
+ return -1;
+ }
+ if (!PyDict_Check(globals)) {
+ PyErr_SetString(PyExc_TypeError,
+ "exec: arg 2 must be a dictionary or None");
return -1;
}
- if (!PyDict_Check(globals) || !PyDict_Check(locals)) {
+ if (!PyDict_Check(locals)) {
PyErr_SetString(PyExc_TypeError,
- "exec 2nd/3rd args must be dict or None");
+ "exec: arg 3 must be a dictionary or None");
return -1;
}
if (PyDict_GetItemString(globals, "__builtins__") == NULL)
PyErr_BadArgument(void)
{
PyErr_SetString(PyExc_TypeError,
- "illegal argument type for built-in operation");
+ "bad argument type for built-in operation");
return 0;
}
/* Watch out for being called to early in the bootstrapping process */
if (PyExc_TypeError) {
PyErr_SetString(PyExc_TypeError,
- "unbound method must be called with class instance 1st argument");
+ "unbound method must be called with instance as first argument");
}
return NULL;
}