Skip to content

tuple.index vs list.index different value errors #121288

Description

@xSpecialFoodx

Bug report

Bug description:

().index(0)  # outputs "tuple.index(x): x not in tuple"
[].index(0)  # outputs "0 is not in list"

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

Activity

  1. Eclips4 commented on Jul 2, 2024

    @Eclips4
    Member

    Yes, the output from list.index is more obvious, in my opinion.
    I think we should treat this issue as a type-feature rather than a type-bug, since there is no bug, it's just a place where we can improve the behavior.

  2. added
    type-featureA feature request or enhancement
    and removed
    type-bugAn unexpected behavior, bug, or error
    on Jul 2, 2024
  3. kumaraditya303 commented on Jul 3, 2024

    @kumaraditya303
    Contributor

    +1 SGTM

  4. picnixz commented on Jul 3, 2024

    @picnixz
    Member

    I'll take that one if possible

  5. picnixz commented on Jul 3, 2024

    @picnixz
    Member

    By the way, for list.remove:

    PyErr_SetString(PyExc_ValueError, "list.remove(x): x not in list");

    So, should I also change this one?

  6. Eclips4 commented on Jul 3, 2024

    @Eclips4
    Member

    Yes, let's also improve that one.

  7. picnixz commented on Jul 3, 2024

    @picnixz
    Member

    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.

  8. nineteendo commented on Jul 3, 2024

    @nineteendo
    Contributor

    Thanks for taking the time to look through previous issues. This tends to be forgotten.

  9. removed their assignment
    on Jul 3, 2024
  10. added a commit that references this issue on Jul 5, 2024
  11. serhiy-storchaka commented on Jul 5, 2024

    @serhiy-storchaka
    Member

    On other hand, error message like "tuple.index(x): x not in tuple" is not especially good:

    • it repeats the type name twice
    • it uses "x"

    Something like "value not found in ..." may look better. But I am not sure that it is worth to change error messages in all index() methods.

    BTW, for str, bytes and bytearray the error messages are different: "substring not found" and "subsection not found".

  12. nineteendo commented on Jul 5, 2024

    @nineteendo
    Contributor

    How about "value not found"? That would also be consistent with str.index(), bytes.index(), and bytearray.index().

  13. added a commit that references this issue on Jul 5, 2024
  14. nineteendo commented on Jul 6, 2024

    @nineteendo
    Contributor

    Note that the issue was:

    tuple.index vs list.index different value error

    That's now fixed, so this should be closed as "completed".

  15. vstinner commented on Jul 6, 2024

    @vstinner
    Member

    I didn't see that a PR was merged.

  16. added a commit that references this issue on Jul 11, 2024
  17. added a commit that references this issue on Jul 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-featureA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions