-
-
Notifications
You must be signed in to change notification settings - Fork 33.1k
gh-137508: Unify error messages for index() and remove() #139696
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Unify error messages for the :meth:`!index` and :meth:`!remove` methods of | ||
classes :class:`list`, :class:`tuple`, :class:`range`, :class:`memoryview`, | ||
:class:`str`, :class:`bytes`, :class:`bytearray`, :class:`array.array`, and | ||
:class:`collections.deque`, and the :func:`operator.indexOf` function. | ||
Improve error message for :meth:`xml.etree.ElementTree.Element.remove`. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3306,7 +3306,7 @@ list_index_impl(PyListObject *self, PyObject *value, Py_ssize_t start, | |
else if (cmp < 0) | ||
return NULL; | ||
} | ||
PyErr_SetString(PyExc_ValueError, "list.index(x): x not in list"); | ||
PyErr_SetString(PyExc_ValueError, "value not in list"); | ||
return NULL; | ||
} | ||
|
||
|
@@ -3376,7 +3376,7 @@ list_remove_impl(PyListObject *self, PyObject *value) | |
else if (cmp < 0) | ||
return NULL; | ||
} | ||
PyErr_SetString(PyExc_ValueError, "list.remove(x): x not in list"); | ||
PyErr_SetString(PyExc_ValueError, "value not in list"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To me this just makes the messages slightly less informative. Personally, I don't see this as an improvement. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not so strong proponent of this change, but I think that there is a benefit of having unified error messages whether it is possible. I'll left this PR until we have an overwhelming support of any variant. |
||
return NULL; | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer the message be left as-is.