[issue22077] Improve the error message for various sequences

Claudiu Popa report at bugs.python.org
Sat Jul 26 10:52:10 CEST 2014


New submission from Claudiu Popa:

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 "<stdin>", line 1, in <module>
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 "<stdin>", line 1, in <module>
TypeError: range indices must be integers or slices, not str


The attached patch improves these error messages.

----------
files: proper_error.patch
keywords: patch
messages: 224029
nosy: Claudiu.Popa
priority: normal
severity: normal
status: open
title: Improve the error message for various sequences
type: enhancement
versions: Python 3.5
Added file: http://bugs.python.org/file36104/proper_error.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue22077>
_______________________________________


More information about the Python-bugs-list mailing list