Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-96844: Improve error message of list.remove #106455

Merged
merged 3 commits into from
Jul 5, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
gh-96844: Improve error message of list.remove
  • Loading branch information
corona10 committed Jul 5, 2023
commit 1bfde406e750b95938c5d856a3379436980f996a
6 changes: 3 additions & 3 deletions Doc/library/doctest.rst
Original file line number Diff line number Diff line change
Expand Up @@ -409,10 +409,10 @@
>>> [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

Check warning on line 414 in Doc/library/doctest.rst

View workflow job for this annotation

GitHub Actions / Docs / Docs

Inline literal start-string without end-string.
`` 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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improve error message of :meth:`list.remove`. Patch by Dong-hee Na.
2 changes: 1 addition & 1 deletion Objects/listobject.c
Original file line number Diff line number Diff line change
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
Loading