Issue 22077: Improve the error message for various sequences (original) (raw)
For a couple of sequences (bytes, list, tuple, bytearray), the error when using an invalid sequence index is misleading, because it says that only integers are allowed, while slices are allowed too.
a = [] a['python'] Traceback (most recent call last): File "", line 1, in TypeError: list indices must be integers, not str
For instance, here's how range does it:
range(1)['a'] Traceback (most recent call last): File "", line 1, in TypeError: range indices must be integers or slices, not str
The attached patch improves these error messages.