This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Improve the error message for various sequences
Type: enhancement Stage: resolved
Components: Versions: Python 3.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: terry.reedy Nosy List: Claudiu.Popa, python-dev, terry.reedy
Priority: normal Keywords: patch

Created on 2014-07-26 08:52 by Claudiu.Popa, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
proper_error.patch Claudiu.Popa, 2014-07-26 08:52 review
Messages (3)
msg224029 - (view) Author: PCManticore (Claudiu.Popa) * (Python triager) Date: 2014-07-26 08:52
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.
msg224535 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2014-08-02 05:31
New changeset 02d6d3a7a181 by Terry Jan Reedy in branch 'default':
Issue #22077: Improve index error messages for bytearrays, bytes, lists, and
http://hg.python.org/cpython/rev/02d6d3a7a181
msg224536 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2014-08-02 05:32
while at it, I changed bytearray messages to include bad type as other do.
History
Date User Action Args
2022-04-11 14:58:06adminsetgithub: 66275
2014-08-02 05:32:25terry.reedysetstatus: open -> closed
resolution: fixed
messages: + msg224536

stage: resolved
2014-08-02 05:31:03python-devsetnosy: + python-dev
messages: + msg224535
2014-08-01 18:18:46terry.reedysetassignee: terry.reedy

nosy: + terry.reedy
2014-07-26 08:52:10Claudiu.Popacreate