mirror of https://github.com/python/cpython
gh-96844: Improve error message of list.remove (gh-106455)
This commit is contained in:
parent
c16ea94abc
commit
217f47d6e5
|
@ -409,10 +409,10 @@ Simple example::
|
|||
>>> [1, 2, 3].remove(42)
|
||||
Traceback (most recent call last):
|
||||
File "<stdin>", line 1, in <module>
|
||||
ValueError: list.remove(x): x not in list
|
||||
ValueError: 42 is not in list
|
||||
|
||||
That doctest succeeds if :exc:`ValueError` is raised, with the ``list.remove(x):
|
||||
x not in list`` detail as shown.
|
||||
That doctest succeeds if :exc:`ValueError` is raised, with the ``42 is 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
|
||||
|
|
|
@ -328,7 +328,7 @@ class ElementTreeTest(unittest.TestCase):
|
|||
self.serialize_check(element, '<tag key="value" />') # 5
|
||||
with self.assertRaises(ValueError) as cm:
|
||||
element.remove(subelement)
|
||||
self.assertEqual(str(cm.exception), 'list.remove(x): x not in list')
|
||||
self.assertIn('not in list', str(cm.exception))
|
||||
self.serialize_check(element, '<tag key="value" />') # 6
|
||||
element[0:0] = [subelement, subelement, subelement]
|
||||
self.serialize_check(element[1], '<subtag />')
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Improve error message of :meth:`list.remove`. Patch by Dong-hee Na.
|
|
@ -2694,7 +2694,7 @@ list_remove(PyListObject *self, PyObject *value)
|
|||
else if (cmp < 0)
|
||||
return NULL;
|
||||
}
|
||||
PyErr_SetString(PyExc_ValueError, "list.remove(x): x not in list");
|
||||
PyErr_Format(PyExc_ValueError, "%R is not in list", value);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue