Author: Armin Rigo <ar...@tunes.org> Branch: py3.5 Changeset: r87773:1bc8b7459f16 Date: 2016-10-14 11:27 +0200 http://bitbucket.org/pypy/pypy/changeset/1bc8b7459f16/
Log: Improve error message diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py --- a/pypy/interpreter/baseobjspace.py +++ b/pypy/interpreter/baseobjspace.py @@ -1375,7 +1375,8 @@ except OperationError as err: if objdescr is None or not err.match(self, self.w_TypeError): raise - raise oefmt(self.w_TypeError, "%s must be an integer, not %T", + raise oefmt(self.w_TypeError, + "%s indices must be integers or slices, not %T", objdescr, w_obj) try: # allow_conversion=False it's not really necessary because the diff --git a/pypy/interpreter/test/test_objspace.py b/pypy/interpreter/test/test_objspace.py --- a/pypy/interpreter/test/test_objspace.py +++ b/pypy/interpreter/test/test_objspace.py @@ -238,8 +238,8 @@ try: self.space.getindex_w(self.space.w_tuple, None, "foobar") except OperationError as e: - assert e.match(self.space, self.space.w_TypeError) - assert "foobar" in e.errorstr(self.space) + assert e.errorstr(self.space) == ( + "TypeError: foobar indices must be integers or slices, not type") else: assert 0, "should have raised" diff --git a/pypy/objspace/std/bytearrayobject.py b/pypy/objspace/std/bytearrayobject.py --- a/pypy/objspace/std/bytearrayobject.py +++ b/pypy/objspace/std/bytearrayobject.py @@ -358,8 +358,7 @@ _setitem_slice_helper(space, self.data, start, step, slicelength, sequence2, empty_elem='\x00') else: - idx = space.getindex_w(w_index, space.w_IndexError, - "bytearray index") + idx = space.getindex_w(w_index, space.w_IndexError, "bytearray") try: self.data[idx] = getbytevalue(space, w_other) except IndexError: @@ -371,8 +370,7 @@ len(self.data)) _delitem_slice_helper(space, self.data, start, step, slicelength) else: - idx = space.getindex_w(w_idx, space.w_IndexError, - "bytearray index") + idx = space.getindex_w(w_idx, space.w_IndexError, "bytearray") try: del self.data[idx] except IndexError: diff --git a/pypy/objspace/std/listobject.py b/pypy/objspace/std/listobject.py --- a/pypy/objspace/std/listobject.py +++ b/pypy/objspace/std/listobject.py @@ -561,7 +561,7 @@ return self.getslice(start, stop, step, slicelength) try: - index = space.getindex_w(w_index, space.w_IndexError, "list index") + index = space.getindex_w(w_index, space.w_IndexError, "list") return self.getitem(index) except IndexError: raise oefmt(space.w_IndexError, "list index out of range") @@ -578,7 +578,7 @@ self.setslice(start, step, slicelength, w_other) return - idx = space.getindex_w(w_index, space.w_IndexError, "list index") + idx = space.getindex_w(w_index, space.w_IndexError, "list") try: self.setitem(idx, w_any) except IndexError: @@ -591,7 +591,7 @@ self.deleteslice(start, step, slicelength) return - idx = space.getindex_w(w_idx, space.w_IndexError, "list index") + idx = space.getindex_w(w_idx, space.w_IndexError, "list") if idx < 0: idx += self.length() try: diff --git a/pypy/objspace/std/stringmethods.py b/pypy/objspace/std/stringmethods.py --- a/pypy/objspace/std/stringmethods.py +++ b/pypy/objspace/std/stringmethods.py @@ -130,7 +130,7 @@ ret = _descr_getslice_slowpath(selfvalue, start, step, sl) return self._new_from_list(ret) - index = space.getindex_w(w_index, space.w_IndexError, "string index") + index = space.getindex_w(w_index, space.w_IndexError, "string") return self._getitem_result(space, index) def _getitem_result(self, space, index): diff --git a/pypy/objspace/std/tupleobject.py b/pypy/objspace/std/tupleobject.py --- a/pypy/objspace/std/tupleobject.py +++ b/pypy/objspace/std/tupleobject.py @@ -189,7 +189,7 @@ def descr_getitem(self, space, w_index): if isinstance(w_index, W_SliceObject): return self._getslice(space, w_index) - index = space.getindex_w(w_index, space.w_IndexError, "tuple index") + index = space.getindex_w(w_index, space.w_IndexError, "tuple") return self.getitem(space, index) def _getslice(self, space, w_index): _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit