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 petri.lehtinen
Recipients petri.lehtinen
Date 2011-11-05.20:49:36
SpamBayes Score 4.9960036e-15
Marked as misclassified No
Message-id <1320526177.89.0.678573577515.issue13349@psf.upfronthosting.co.za>
In-reply-to
Content
For example:

>>> (1, 2, 3).index(4)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: tuple.index(x): x not in tuple

The "x not in tuple" error message should be replaced with "4 is not in tuple". list.index() already does this (see #7252):

>>> [1, 2, 3].index(4)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: 4 is not in list

Although in #7252 it was claimed that no other place in stdlib has this error message, I found many occurences:

Modules/_collectionsmodule.c:    PyErr_SetString(PyExc_ValueError, "deque.remove(x): x not in deque"
Modules/_elementtree.c:            "list.remove(x): x not in list"
Modules/_elementtree.c:            "list.remove(x): x not in list"
Modules/arraymodule.c:    PyErr_SetString(PyExc_ValueError, "array.index(x): x not in list");
Modules/arraymodule.c:    PyErr_SetString(PyExc_ValueError, "array.remove(x): x not in list");
Objects/abstract.c:                    "sequence.index(x): x not in sequence");
Objects/listobject.c:    PyErr_SetString(PyExc_ValueError, "list.remove(x): x not in list");
Objects/tupleobject.c:    PyErr_SetString(PyExc_ValueError, "tuple.index(x): x not in tuple");

There's also documentation and tests that depend on this actual error message:

Doc/library/doctest.rst:   ValueError: list.remove(x): x not in list
Lib/test/test_xml_etree.py:    ValueError: list.remove(x): x not in list

#7252 was fixed in r76058, and it's quite a lot of code. I think it could be done more easily using PyUnicode_FromFormat() and the %R format.
History
Date User Action Args
2011-11-05 20:49:38petri.lehtinensetrecipients: + petri.lehtinen
2011-11-05 20:49:37petri.lehtinensetmessageid: <1320526177.89.0.678573577515.issue13349@psf.upfronthosting.co.za>
2011-11-05 20:49:37petri.lehtinenlinkissue13349 messages
2011-11-05 20:49:36petri.lehtinencreate