Skip to content

Commit f6cdc6b

Browse files
authored
Revert "pythongh-96844: Improve error message of list.remove (pythongh-106455)" (python#116956)
This reverts commit 217f47d.
1 parent 2a4cbf1 commit f6cdc6b

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

Doc/library/doctest.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -430,10 +430,10 @@ Simple example::
430430
>>> [1, 2, 3].remove(42)
431431
Traceback (most recent call last):
432432
File "<stdin>", line 1, in <module>
433-
ValueError: 42 is not in list
433+
ValueError: list.remove(x): x not in list
434434

435-
That doctest succeeds if :exc:`ValueError` is raised, with the ``42 is not in list``
436-
detail as shown.
435+
That doctest succeeds if :exc:`ValueError` is raised, with the ``list.remove(x):
436+
x not in list`` detail as shown.
437437

438438
The expected output for an exception must start with a traceback header, which
439439
may be either of the following two lines, indented the same as the first line of

Lib/test/test_xml_etree.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ def test_simpleops(self):
329329
self.serialize_check(element, '<tag key="value" />') # 5
330330
with self.assertRaises(ValueError) as cm:
331331
element.remove(subelement)
332-
self.assertIn('not in list', str(cm.exception))
332+
self.assertEqual(str(cm.exception), 'list.remove(x): x not in list')
333333
self.serialize_check(element, '<tag key="value" />') # 6
334334
element[0:0] = [subelement, subelement, subelement]
335335
self.serialize_check(element[1], '<subtag />')

Objects/listobject.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -3194,7 +3194,7 @@ list_remove_impl(PyListObject *self, PyObject *value)
31943194
else if (cmp < 0)
31953195
return NULL;
31963196
}
3197-
PyErr_Format(PyExc_ValueError, "%R is not in list", value);
3197+
PyErr_SetString(PyExc_ValueError, "list.remove(x): x not in list");
31983198
return NULL;
31993199
}
32003200

0 commit comments

Comments
 (0)