New submission from Petri Lehtinen <pe...@digip.org>: 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. ---------- messages: 147109 nosy: petri.lehtinen priority: normal severity: normal status: open title: Uninformal error message in index() and remove() functions _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue13349> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com