diff options
author | Georg Brandl <georg@python.org> | 2006-11-19 08:48:30 (GMT) |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2006-11-19 08:48:30 (GMT) |
commit | 283a1353a0834d53b230b22e8db9e7b4fcd220d0 (patch) | |
tree | 38cdb53e185f70ebb4c288f28b43a2dbcc39e17f /Objects | |
parent | db4f255c61d11836f734cea3329145a0f370f317 (diff) | |
download | cpython-283a1353a0834d53b230b22e8db9e7b4fcd220d0.zip cpython-283a1353a0834d53b230b22e8db9e7b4fcd220d0.tar.gz cpython-283a1353a0834d53b230b22e8db9e7b4fcd220d0.tar.bz2 |
Patch [ 1586791 ] better error msgs for some TypeErrors
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/listobject.c | 15 | ||||
-rw-r--r-- | Objects/stringobject.c | 16 | ||||
-rw-r--r-- | Objects/tupleobject.c | 5 |
3 files changed, 22 insertions, 14 deletions
diff --git a/Objects/listobject.c b/Objects/listobject.c index a1ac2cb..3083b5f 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -946,9 +946,10 @@ islt(PyObject *x, PyObject *y, PyObject *compare) if (res == NULL) return -1; if (!PyInt_Check(res)) { + PyErr_Format(PyExc_TypeError, + "comparison function must return int, not %.200s", + res->ob_type->tp_name); Py_DECREF(res); - PyErr_SetString(PyExc_TypeError, - "comparison function must return int"); return -1; } i = PyInt_AsLong(res); @@ -2491,8 +2492,9 @@ list_subscript(PyListObject* self, PyObject* item) } } else { - PyErr_SetString(PyExc_TypeError, - "list indices must be integers"); + PyErr_Format(PyExc_TypeError, + "list indices must be integers, not %.200s", + item->ob_type->tp_name); return NULL; } } @@ -2635,8 +2637,9 @@ list_ass_subscript(PyListObject* self, PyObject* item, PyObject* value) } } else { - PyErr_SetString(PyExc_TypeError, - "list indices must be integers"); + PyErr_Format(PyExc_TypeError, + "list indices must be integers, not %.200s", + item->ob_type->tp_name); return -1; } } diff --git a/Objects/stringobject.c b/Objects/stringobject.c index aa2fd87..5d31c38 100644 --- a/Objects/stringobject.c +++ b/Objects/stringobject.c @@ -1071,8 +1071,9 @@ string_contains(PyObject *str_obj, PyObject *sub_obj) return PyUnicode_Contains(str_obj, sub_obj); #endif if (!PyString_Check(sub_obj)) { - PyErr_SetString(PyExc_TypeError, - "'in <string>' requires string as left operand"); + PyErr_Format(PyExc_TypeError, + "'in <string>' requires string as left operand, " + "not %.200s", sub_obj->ob_type->tp_name); return -1; } } @@ -1240,8 +1241,9 @@ string_subscript(PyStringObject* self, PyObject* item) } } else { - PyErr_SetString(PyExc_TypeError, - "string indices must be integers"); + PyErr_Format(PyExc_TypeError, + "string indices must be integers, not %.200s", + item->ob_type->tp_name); return NULL; } } @@ -4148,7 +4150,8 @@ formatfloat(char *buf, size_t buflen, int flags, double x; x = PyFloat_AsDouble(v); if (x == -1.0 && PyErr_Occurred()) { - PyErr_SetString(PyExc_TypeError, "float argument required"); + PyErr_Format(PyExc_TypeError, "float argument required, " + "not %.200s", v->ob_type->tp_name); return -1; } if (prec < 0) @@ -4343,7 +4346,8 @@ formatint(char *buf, size_t buflen, int flags, x = PyInt_AsLong(v); if (x == -1 && PyErr_Occurred()) { - PyErr_SetString(PyExc_TypeError, "int argument required"); + PyErr_Format(PyExc_TypeError, "int argument required, not %.200s", + v->ob_type->tp_name); return -1; } if (x < 0 && type == 'u') { diff --git a/Objects/tupleobject.c b/Objects/tupleobject.c index 6f3711f..c85b35a 100644 --- a/Objects/tupleobject.c +++ b/Objects/tupleobject.c @@ -620,8 +620,9 @@ tuplesubscript(PyTupleObject* self, PyObject* item) } } else { - PyErr_SetString(PyExc_TypeError, - "tuple indices must be integers"); + PyErr_Format(PyExc_TypeError, + "tuple indices must be integers, not %.200s", + item->ob_type->tp_name); return NULL; } } |