From: Terry Jan Reedy Date: Sat, 2 Aug 2014 05:30:37 +0000 (-0400) Subject: Issue #22077: Improve index error messages for bytearrays, bytes, lists, and X-Git-Tag: v3.5.0a1~1144 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ffff1440d118cae189a6c2baf595dda52cdc7c3a;p=python Issue #22077: Improve index error messages for bytearrays, bytes, lists, and tuples by adding 'or slices'. Added ', not tp_name); return NULL; } } @@ -650,7 +652,9 @@ bytearray_ass_subscript(PyByteArrayObject *self, PyObject *index, PyObject *valu } } else { - PyErr_SetString(PyExc_TypeError, "bytearray indices must be integer"); + PyErr_Format(PyExc_TypeError, + "bytearray indices must be integers or slices, not %.200s", + Py_TYPE(index)->tp_name); return -1; } diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c index aff09cd58d..ca565eb566 100644 --- a/Objects/bytesobject.c +++ b/Objects/bytesobject.c @@ -999,7 +999,7 @@ bytes_subscript(PyBytesObject* self, PyObject* item) } else { PyErr_Format(PyExc_TypeError, - "byte indices must be integers, not %.200s", + "byte indices must be integers or slices, not %.200s", Py_TYPE(item)->tp_name); return NULL; } diff --git a/Objects/listobject.c b/Objects/listobject.c index fd5a72af8d..e7c4c82703 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -2444,7 +2444,7 @@ list_subscript(PyListObject* self, PyObject* item) } else { PyErr_Format(PyExc_TypeError, - "list indices must be integers, not %.200s", + "list indices must be integers or slices, not %.200s", item->ob_type->tp_name); return NULL; } @@ -2608,7 +2608,7 @@ list_ass_subscript(PyListObject* self, PyObject* item, PyObject* value) } else { PyErr_Format(PyExc_TypeError, - "list indices must be integers, not %.200s", + "list indices must be integers or slices, not %.200s", item->ob_type->tp_name); return -1; } diff --git a/Objects/tupleobject.c b/Objects/tupleobject.c index 6fd4db3ae0..753097bef2 100644 --- a/Objects/tupleobject.c +++ b/Objects/tupleobject.c @@ -746,7 +746,7 @@ tuplesubscript(PyTupleObject* self, PyObject* item) } else { PyErr_Format(PyExc_TypeError, - "tuple indices must be integers, not %.200s", + "tuple indices must be integers or slices, not %.200s", Py_TYPE(item)->tp_name); return NULL; }