]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Revert "gh-96844: Improve error message of list.remove (gh-106455)" (#116956)
authorVictor Stinner <vstinner@python.org>
Mon, 18 Mar 2024 13:54:45 +0000 (14:54 +0100)
committerGitHub <noreply@github.com>
Mon, 18 Mar 2024 13:54:45 +0000 (13:54 +0000)
This reverts commit 217f47d6e5e56bca78b8556e910cd00890f6f84a.

Doc/library/doctest.rst
Lib/test/test_xml_etree.py
Objects/listobject.c

index 1bfcd69f72df2ef3255ad55b0af469fe531bdbbc..835a3a76806148768a924fcee87332735c944581 100644 (file)
@@ -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
index 14df482ba6c207f60969c779c0243bf23b447e5f..3f01a79cc05efda068a3e5ddfe27996b235b7e6b 100644 (file)
@@ -329,7 +329,7 @@ class ElementTreeTest(unittest.TestCase):
         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 />')
index 6f919ce02b3ce28ce2ee06cdfd32865f466d4a09..096043bb3d3c51345588b8c851f62f74baac1e52 100644 (file)
@@ -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;
 }