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.

Author terry.reedy
Recipients terry.reedy
Date 2009-02-23.18:38:26
SpamBayes Score 3.244274e-09
Marked as misclassified No
Message-id <1235414311.83.0.833112713041.issue5353@psf.upfronthosting.co.za>
In-reply-to
Content
Currently: >>> l=[]; l[1] # 3.0.1
...
IndexError: list index out of range

Assuming that negative indexes are converted before the range test is
made, I would like to see
"IndexError: list index 1 not in range(0)", ie,
"IndexError: list index {0} not in range({1})".format(<index>,
len(<sequence>)).

The 'in' operator still works with Py3 range objects, so the suggested
Python-level check is still valid.

I did not add 2.6/3.0 only because I don't know if improved error
messages are acceptable in bug-fix releases.

Same request for other sequence IndexError messages:
>>> t=(); t[0]
IndexError: tuple index out of range

>>> s=''; s[0] # 3.0
IndexError: string index out of range

>>> b=b''; b[0]
IndexError: index out of range # *** 'bytes' uniquely missing here ***

>>> ba=bytearray(b); ba[0]
IndexError: bytearray index out of range

Is the check factored out as a macro (or function) so one change would
change all of these?

Similar errors with dict (tersely) give the bad key already:
>>> d={}; d[1]
...
KeyError: 1

-------------------------
The may be superficially similar to request #654558, but that was vague
and was closed as a duplicate of #569574, which is definitely about a
different issue.  I did not see anything else in the search results.
History
Date User Action Args
2009-02-23 18:38:32terry.reedysetrecipients: + terry.reedy
2009-02-23 18:38:31terry.reedysetmessageid: <1235414311.83.0.833112713041.issue5353@psf.upfronthosting.co.za>
2009-02-23 18:38:28terry.reedylinkissue5353 messages
2009-02-23 18:38:26terry.reedycreate