Message82634
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. |
|
Date |
User |
Action |
Args |
2009-02-23 18:38:32 | terry.reedy | set | recipients:
+ terry.reedy |
2009-02-23 18:38:31 | terry.reedy | set | messageid: <1235414311.83.0.833112713041.issue5353@psf.upfronthosting.co.za> |
2009-02-23 18:38:28 | terry.reedy | link | issue5353 messages |
2009-02-23 18:38:26 | terry.reedy | create | |
|