Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Bugs

[issue7252] list().index() should provide better error reporting

 

 

Python bugs RSS feed   Index | Next | Previous | View Threaded


report at bugs

Nov 2, 2009, 3:59 AM

Post #1 of 5 (218 views)
Permalink
[issue7252] list().index() should provide better error reporting

New submission from djc <dirkjan [at] ochtman>:

>>> a = 'b'
>>> [].index(a)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: list.index(x): x not in list

This is suboptimal. IMO it would be much more useful if the ValueError
reported the actual value that wasn't in the list, like this:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: list.index('b'): 'b' not in list

The error in general doesn't really seem to fit in, repeating the code
but with a fake variable name in it. In real contexts, it's mostly just
repeating what's there on a previous line:

File "/home/watt/src/dawkins/ttlib.py", line 86, in shift
bits.append(SHIFTS.index(rest.split('_')[0]))
ValueError: list.index(x): x not in list

So maybe just make it "'b' not in list"? Or do we really need a
reference to the index() method in there?

----------
components: Library (Lib)
messages: 94825
nosy: djc
severity: normal
status: open
title: list().index() should provide better error reporting
versions: Python 2.6

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue7252>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Nov 2, 2009, 3:59 AM

Post #2 of 5 (197 views)
Permalink
[issue7252] list().index() should provide better error reporting [In reply to]

djc <dirkjan [at] ochtman> added the comment:

FWIW, quickly grepping through the raises of ValueErrors in the 2.6
stdlib doesn't bring up any other usage of repeat-with-fake-variable-x.

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue7252>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Nov 2, 2009, 7:07 AM

Post #3 of 5 (187 views)
Permalink
[issue7252] list().index() should provide better error reporting [In reply to]

Benjamin Peterson <benjamin [at] python> added the comment:

How's "object is not in list"?

----------
nosy: +benjamin.peterson

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue7252>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Nov 2, 2009, 7:14 AM

Post #4 of 5 (190 views)
Permalink
[issue7252] list().index() should provide better error reporting [In reply to]

djc <dirkjan [at] ochtman> added the comment:

I want the actual value in there, though! So I can spot the bug.

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue7252>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Nov 2, 2009, 8:15 AM

Post #5 of 5 (190 views)
Permalink
[issue7252] list().index() should provide better error reporting [In reply to]

Benjamin Peterson <benjamin [at] python> added the comment:

r76058 should do the trick.

----------
resolution: -> accepted
status: open -> closed

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue7252>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com

Python bugs RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.