diff options
author | Fred Drake <fdrake@acm.org> | 2000-06-01 02:02:46 (GMT) |
---|---|---|
committer | Fred Drake <fdrake@acm.org> | 2000-06-01 02:02:46 (GMT) |
commit | 137507ea0308fcdab66c1eee700048c41ed7a7d7 (patch) | |
tree | d0be03f809710a00ebfe02b7d332531fda764c99 | |
parent | b5fc749c8b809f8ebab74cebff4153880236ca33 (diff) | |
download | cpython-137507ea0308fcdab66c1eee700048c41ed7a7d7.zip cpython-137507ea0308fcdab66c1eee700048c41ed7a7d7.tar.gz cpython-137507ea0308fcdab66c1eee700048c41ed7a7d7.tar.bz2 |
Michael Hudson <mwh21@cam.ac.uk>:
Removed PyErr_BadArgument() calls and replaced them with more useful
error messages.
-rw-r--r-- | Modules/arraymodule.c | 11 | ||||
-rw-r--r-- | Modules/posixmodule.c | 7 | ||||
-rw-r--r-- | Modules/structmodule.c | 3 |
3 files changed, 14 insertions, 7 deletions
diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c index 9a09c7d..7966e0a 100644 --- a/Modules/arraymodule.c +++ b/Modules/arraymodule.c @@ -540,7 +540,9 @@ array_concat(a, bb) int size; arrayobject *np; 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; } #define b ((arrayobject *)bb) @@ -613,7 +615,9 @@ array_ass_slice(a, ilow, ihigh, v) } } else { - PyErr_BadArgument(); + PyErr_Format(PyExc_TypeError, + "can only assign array (not \"%.200s\") to array slice", + v->ob_type->tp_name); return -1; } if (ilow < 0) @@ -821,7 +825,8 @@ array_reverse(self, args) char tmp[sizeof(double)]; /* Assume that's the max item size */ if (args != NULL) { - PyErr_BadArgument(); + PyErr_SetString(PyExc_TypeError, + "<array>.reverse requires exactly 0 arguments"); return NULL; } diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 1ca3826..20efb0e 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -1562,8 +1562,7 @@ posix_spawnv(self, args) getitem = PyTuple_GetItem; } else { - badarg: - PyErr_BadArgument(); + PyErr_SetString(PyExc_TypeError, "argv must be tuple or list"); return NULL; } @@ -1573,7 +1572,9 @@ posix_spawnv(self, args) for (i = 0; i < argc; i++) { if (!PyArg_Parse((*getitem)(argv, i), "s", &argvlist[i])) { PyMem_DEL(argvlist); - goto badarg; + PyErr_SetString(PyExc_TypeError, + "all arguments must be strings"); + return NULL; } } argvlist[argc] = NULL; diff --git a/Modules/structmodule.c b/Modules/structmodule.c index 0a706a9..d872e31 100644 --- a/Modules/structmodule.c +++ b/Modules/structmodule.c @@ -1128,7 +1128,8 @@ struct_pack(self, args) if (args == NULL || !PyTuple_Check(args) || (n = PyTuple_Size(args)) < 1) { - PyErr_BadArgument(); + PyErr_SetString(PyExc_TypeError, + "struct.pack requires at least one argument"); return NULL; } format = PyTuple_GetItem(args, 0); |