classification
Title: tuple.index() could return a more explicit error message
Type: enhancement Stage: resolved
Components: Versions: Python 3.8
process
Status: closed Resolution: fixed
Dependencies: Superseder: Non-informative error message in index() and remove() functions
View: 13349
Assigned To: Nosy List: Cyril Roelandt, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2018-05-17 16:20 by Cyril Roelandt, last changed 2018-05-17 16:47 by serhiy.storchaka. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 6944 closed python-dev, 2018-05-17 16:35
Messages (2)
msg316955 - (view) Author: Cyril Roelandt (Cyril Roelandt) * Date: 2018-05-17 16:20
The tuple.index() method returns an error message that does not allow users to know what element was being looked for inside the tuple:

>>> ().index(1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: tuple.index(x): x not in tuple

The list.index() method has a much better error message:

>>> [].index(1)   
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: 1 is not in list

We could improve tuple.index() so that its behaviour becomes similar to that of list.index().
msg316964 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-05-17 16:47
This is a duplicate of issue13349.
History
Date User Action Args
2018-05-17 16:47:25serhiy.storchakasetstatus: open -> closed

superseder: Non-informative error message in index() and remove() functions

nosy: + serhiy.storchaka
messages: + msg316964
resolution: fixed
stage: patch review -> resolved
2018-05-17 16:35:46python-devsetkeywords: + patch
stage: patch review
pull_requests: + pull_request6612
2018-05-17 16:20:20Cyril Roelandtcreate