https://github.com/python/cpython/commit/f6cdc6b4a191b75027de342aa8b5d344fb31313e commit: f6cdc6b4a191b75027de342aa8b5d344fb31313e branch: main author: Victor Stinner <vstin...@python.org> committer: vstinner <vstin...@python.org> date: 2024-03-18T13:54:45Z summary:
Revert "gh-96844: Improve error message of list.remove (gh-106455)" (#116956) This reverts commit 217f47d6e5e56bca78b8556e910cd00890f6f84a. files: M Doc/library/doctest.rst M Lib/test/test_xml_etree.py M Objects/listobject.c diff --git a/Doc/library/doctest.rst b/Doc/library/doctest.rst index 1bfcd69f72df2e..835a3a76806148 100644 --- a/Doc/library/doctest.rst +++ b/Doc/library/doctest.rst @@ -430,10 +430,10 @@ Simple example:: >>> [1, 2, 3].remove(42) Traceback (most recent call last): File "<stdin>", line 1, in <module> - ValueError: 42 is not in list + ValueError: list.remove(x): x not in list -That doctest succeeds if :exc:`ValueError` is raised, with the ``42 is not in list`` -detail as shown. +That doctest succeeds if :exc:`ValueError` is raised, with the ``list.remove(x): +x not in list`` detail as shown. The expected output for an exception must start with a traceback header, which may be either of the following two lines, indented the same as the first line of diff --git a/Lib/test/test_xml_etree.py b/Lib/test/test_xml_etree.py index 14df482ba6c207..3f01a79cc05efd 100644 --- a/Lib/test/test_xml_etree.py +++ b/Lib/test/test_xml_etree.py @@ -329,7 +329,7 @@ def test_simpleops(self): self.serialize_check(element, '<tag key="value" />') # 5 with self.assertRaises(ValueError) as cm: element.remove(subelement) - self.assertIn('not in list', str(cm.exception)) + self.assertEqual(str(cm.exception), 'list.remove(x): x not in list') self.serialize_check(element, '<tag key="value" />') # 6 element[0:0] = [subelement, subelement, subelement] self.serialize_check(element[1], '<subtag />') diff --git a/Objects/listobject.c b/Objects/listobject.c index 6f919ce02b3ce2..096043bb3d3c51 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -3194,7 +3194,7 @@ list_remove_impl(PyListObject *self, PyObject *value) else if (cmp < 0) return NULL; } - PyErr_Format(PyExc_ValueError, "%R is not in list", value); + PyErr_SetString(PyExc_ValueError, "list.remove(x): x not in list"); return NULL; } _______________________________________________ Python-checkins mailing list -- python-checkins@python.org To unsubscribe send an email to python-checkins-le...@python.org https://mail.python.org/mailman3/lists/python-checkins.python.org/ Member address: arch...@mail-archive.com