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

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

Objects/listobject.c

Lines changed: 6 additions & 2 deletions
Original file line numberOriginal file lineDiff line numberDiff line change
@@ -388,7 +388,9 @@ list_concat(a, bb)
388
int i;
388
int i;
389
PyListObject *np;
389
PyListObject *np;
390
if (!PyList_Check(bb)) {
390
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);
392
return NULL;
394
return NULL;
393
}
395
}
394
#define b ((PyListObject *)bb)
396
#define b ((PyListObject *)bb)
@@ -469,7 +471,9 @@ list_ass_slice(a, ilow, ihigh, v)
469
}
471
}
470
}
472
}
471
else {
473
else {
472-
PyErr_BadArgument();
474+
PyErr_Format(PyExc_TypeError,
475+
"must assign list (not \"%.200s\") to slice",
476+
v->ob_type->tp_name);
473
return -1;
477
return -1;
474
}
478
}
475
if (ilow < 0)
479
if (ilow < 0)

Objects/stringobject.c

Lines changed: 3 additions & 1 deletion
Original file line numberOriginal file lineDiff line numberDiff line change
@@ -293,7 +293,9 @@ string_concat(a, bb)
293
if (!PyString_Check(bb)) {
293
if (!PyString_Check(bb)) {
294
if (PyUnicode_Check(bb))
294
if (PyUnicode_Check(bb))
295
return PyUnicode_Concat((PyObject *)a, bb);
295
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);
297
return NULL;
299
return NULL;
298
}
300
}
299
#define b ((PyStringObject *)bb)
301
#define b ((PyStringObject *)bb)

Objects/tupleobject.c

Lines changed: 3 additions & 1 deletion
Original file line numberOriginal file lineDiff line numberDiff line change
@@ -361,7 +361,9 @@ tupleconcat(a, bb)
361
register int i;
361
register int i;
362
PyTupleObject *np;
362
PyTupleObject *np;
363
if (!PyTuple_Check(bb)) {
363
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);
365
return NULL;
367
return NULL;
366
}
368
}
367
#define b ((PyTupleObject *)bb)
369
#define b ((PyTupleObject *)bb)

0 commit comments

Comments
 (0)