Skip to content

Setting other types than int to range.index() gets the less clear different error messages #139639

@hyperkai

Description

@hyperkai

Bug report

Bug description:

Setting int to range.index() gets the clear error message as shown below:

v = range(5)

print(*v)
# 0 1 2 3 4

print(v.index(7))
# Error

ValueError: 7 is not in range

But setting other types than int to range.index() gets the less clear different error messages as shown below:

v = range(5)

print(*v)
# 0 1 2 3 4

print(v.index(7.5))
print(v.index(7.5+0.0j))
print(v.index('A'))
# Error

ValueError: sequence.index(x): x not in sequence

So they should also be as shown below:

ValueError: 7.5 is not in range
ValueError: 7.5+0.0j is not in range
ValueError: 'A' is not in range

CPython versions tested on:

3.12

Operating systems tested on:

Windows

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)type-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions