New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve IndexError messages with actual values #49603
Comments
Currently: >>> l=[]; l[1] # 3.0.1
...
IndexError: list index out of range Assuming that negative indexes are converted before the range test is The 'in' operator still works with Py3 range objects, so the suggested I did not add 2.6/3.0 only because I don't know if improved error 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 Similar errors with dict (tersely) give the bad key already:
>>> d={}; d[1]
...
KeyError: 1 The may be superficially similar to request bpo-654558, but that was vague |
This issue was discussed two years ago in this thread: http://mail.python.org/pipermail/python-list/2006-December/588224.html Most of the messages under that subject are noise about politeness or http://mail.python.org/pipermail/python-list/2006-December/588377.html The patch addresses only one object type, but does demonstrate a pattern I have not tried to apply the patch to the current trunk, but from a |
See also bpo-1182143. |
This issue is about formatting a value into an error message. Patches to mailing lists tend to get lost. Thank you for finding |
I've seen his patch and am working on my own variant that also attaches |
I'm abandoning this one since I couldn't find a way to do it that didn't impair performance. Unlike C++, it is not uncommon in Python to use exceptions such as IndexError for control flow. There was too little added value in building-out this message to warrant the change (the current message is very clear about what the problem is, it just doesn't dump all the variables involved -- this is not uncommon for python error messages). |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: