-
-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
tuple.index vs list.index different value errors #121288
Comments
Yes, the output from list.index is more obvious, in my opinion. |
+1 SGTM |
I'll take that one if possible |
By the way, for PyErr_SetString(PyExc_ValueError, "list.remove(x): x not in list"); So, should I also change this one? |
Yes, let's also improve that one. |
After digging up a bit, I've concluded that this proposal has more or less been rejected previously (see #57558 (comment)). So I'm not sure I want to change it now. |
Thanks for taking the time to look through previous issues. This tends to be forgotten. |
The same issue is reported regularly:
I think that we should close it from other way: remove the repr of the value from error message for |
Remove the repr of the searched value (which can be arbitrary large) from ValueError messages for list.index(), range.index(), deque.index(), deque.remove() and ShareableList.index(). Make the error messages consistent with error messages for other index() and remove() methods.
On other hand, error message like "tuple.index(x): x not in tuple" is not especially good:
Something like "value not found in ..." may look better. But I am not sure that it is worth to change error messages in all BTW, for |
How about "value not found"? That would also be consistent with |
Make error message for index() methods consistent Remove the repr of the searched value (which can be arbitrary large) from ValueError messages for list.index(), range.index(), deque.index(), deque.remove() and ShareableList.index(). Make the error messages consistent with error messages for other index() and remove() methods.
Latest attempt to include repr(obj) in list error message went bad: |
Note that the issue was:
That's now fixed, so this should be closed as "completed". |
I didn't see that a PR was merged. |
…ythonGH-121395) Make error message for index() methods consistent Remove the repr of the searched value (which can be arbitrary large) from ValueError messages for list.index(), range.index(), deque.index(), deque.remove() and ShareableList.index(). Make the error messages consistent with error messages for other index() and remove() methods.
…ythonGH-121395) Make error message for index() methods consistent Remove the repr of the searched value (which can be arbitrary large) from ValueError messages for list.index(), range.index(), deque.index(), deque.remove() and ShareableList.index(). Make the error messages consistent with error messages for other index() and remove() methods.
Bug report
Bug description:
i think it'd be useful to normalize them to have the same value error, in tuple you can see that the item's value or name isn't even mentioned, unlike in list that the item's value is mentioned, although the name is not.
CPython versions tested on:
3.11
Operating systems tested on:
Windows
Linked PRs
tuple.index
,list.index
andlist.remove
#121308The text was updated successfully, but these errors were encountered: