Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b6a9ada

Browse files
committed
Michael Hudson <[email protected]>:
Removed PyErr_BadArgument() calls and replaced them with more useful error messages.
1 parent 94c3452 commit b6a9ada

3 files changed

Lines changed: 12 additions & 4 deletions

File tree

Objects/listobject.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,9 @@ list_concat(a, bb)
388388
int i;
389389
PyListObject *np;
390390
if (!PyList_Check(bb)) {
391-
PyErr_BadArgument();
391+
PyErr_Format(PyExc_TypeError,
392+
"can only append list (not \"%.200s\") to list",
393+
bb->ob_type->tp_name);
392394
return NULL;
393395
}
394396
#define b ((PyListObject *)bb)
@@ -469,7 +471,9 @@ list_ass_slice(a, ilow, ihigh, v)
469471
}
470472
}
471473
else {
472-
PyErr_BadArgument();
474+
PyErr_Format(PyExc_TypeError,
475+
"must assign list (not \"%.200s\") to slice",
476+
v->ob_type->tp_name);
473477
return -1;
474478
}
475479
if (ilow < 0)

Objects/stringobject.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,9 @@ string_concat(a, bb)
293293
if (!PyString_Check(bb)) {
294294
if (PyUnicode_Check(bb))
295295
return PyUnicode_Concat((PyObject *)a, bb);
296-
PyErr_BadArgument();
296+
PyErr_Format(PyExc_TypeError,
297+
"cannot add type \"%.200s\" to string",
298+
bb->ob_type->tp_name);
297299
return NULL;
298300
}
299301
#define b ((PyStringObject *)bb)

Objects/tupleobject.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,9 @@ tupleconcat(a, bb)
361361
register int i;
362362
PyTupleObject *np;
363363
if (!PyTuple_Check(bb)) {
364-
PyErr_BadArgument();
364+
PyErr_Format(PyExc_TypeError,
365+
"can only append tuple (not \"%.200s\") to tuple",
366+
bb->ob_type->tp_name);
365367
return NULL;
366368
}
367369
#define b ((PyTupleObject *)bb)

0 commit comments

Comments
 (0)