Skip to content

Commit

Permalink
pythongh-96844: Improve error message of list.remove
Browse files Browse the repository at this point in the history
  • Loading branch information
corona10 committed Jul 5, 2023
1 parent 12a9813 commit 1bfde40
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
6 changes: 3 additions & 3 deletions Doc/library/doctest.rst
Expand Up @@ -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
Expand Down
@@ -0,0 +1 @@
Improve error message of :meth:`list.remove`. Patch by Dong-hee Na.
2 changes: 1 addition & 1 deletion Objects/listobject.c
Expand Up @@ -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;
}

Expand Down

0 comments on commit 1bfde40

Please sign in to comment.