Commit 20f6ec2d authored by Fred Drake's avatar Fred Drake

Michael Hudson <mwh21@cam.ac.uk>:

Removed PyErr_BadArgument() calls and replaced them with more useful
error messages.
parent b5a52cea
...@@ -540,7 +540,9 @@ array_concat(a, bb) ...@@ -540,7 +540,9 @@ array_concat(a, bb)
int size; int size;
arrayobject *np; arrayobject *np;
if (!is_arrayobject(bb)) { if (!is_arrayobject(bb)) {
PyErr_BadArgument(); PyErr_Format(PyExc_TypeError,
"can only append array (not \"%.200s\") to array",
bb->ob_type->tp_name);
return NULL; return NULL;
} }
#define b ((arrayobject *)bb) #define b ((arrayobject *)bb)
...@@ -613,7 +615,9 @@ array_ass_slice(a, ilow, ihigh, v) ...@@ -613,7 +615,9 @@ array_ass_slice(a, ilow, ihigh, v)
} }
} }
else { else {
PyErr_BadArgument(); PyErr_Format(PyExc_TypeError,
"can only assign array (not \"%.200s\") to array slice",
v->ob_type->tp_name);
return -1; return -1;
} }
if (ilow < 0) if (ilow < 0)
...@@ -821,7 +825,8 @@ array_reverse(self, args) ...@@ -821,7 +825,8 @@ array_reverse(self, args)
char tmp[sizeof(double)]; /* Assume that's the max item size */ char tmp[sizeof(double)]; /* Assume that's the max item size */
if (args != NULL) { if (args != NULL) {
PyErr_BadArgument(); PyErr_SetString(PyExc_TypeError,
"<array>.reverse requires exactly 0 arguments");
return NULL; return NULL;
} }
......
...@@ -1562,8 +1562,7 @@ posix_spawnv(self, args) ...@@ -1562,8 +1562,7 @@ posix_spawnv(self, args)
getitem = PyTuple_GetItem; getitem = PyTuple_GetItem;
} }
else { else {
badarg: PyErr_SetString(PyExc_TypeError, "argv must be tuple or list");
PyErr_BadArgument();
return NULL; return NULL;
} }
...@@ -1573,7 +1572,9 @@ posix_spawnv(self, args) ...@@ -1573,7 +1572,9 @@ posix_spawnv(self, args)
for (i = 0; i < argc; i++) { for (i = 0; i < argc; i++) {
if (!PyArg_Parse((*getitem)(argv, i), "s", &argvlist[i])) { if (!PyArg_Parse((*getitem)(argv, i), "s", &argvlist[i])) {
PyMem_DEL(argvlist); PyMem_DEL(argvlist);
goto badarg; PyErr_SetString(PyExc_TypeError,
"all arguments must be strings");
return NULL;
} }
} }
argvlist[argc] = NULL; argvlist[argc] = NULL;
......
...@@ -1128,7 +1128,8 @@ struct_pack(self, args) ...@@ -1128,7 +1128,8 @@ struct_pack(self, args)
if (args == NULL || !PyTuple_Check(args) || if (args == NULL || !PyTuple_Check(args) ||
(n = PyTuple_Size(args)) < 1) (n = PyTuple_Size(args)) < 1)
{ {
PyErr_BadArgument(); PyErr_SetString(PyExc_TypeError,
"struct.pack requires at least one argument");
return NULL; return NULL;
} }
format = PyTuple_GetItem(args, 0); format = PyTuple_GetItem(args, 0);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment