[New-bugs-announce] [issue7252] list().index() should provide better error reporting

djc report at bugs.python.org
Mon Nov 2 12:59:13 CET 2009


New submission from djc <dirkjan at ochtman.nl>:

>>> 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.python.org>
<http://bugs.python.org/issue7252>
_______________________________________


More information about the New-bugs-announce mailing list