pylint
pylint copied to clipboard
False positive invalid-sequence-index using properties of range object as index
Bug description
Using the `start` or `stop` properties of a `range` object to index a `Sequence` raises a false E1126 error even though both are integers. The following code shows the error.
l = ["A", "B", "C"]
r = range(3)
print(l[r.start])
print(l[r.stop])
### Configuration
_No response_
### Command used
```shell
pylint -E test.py
Pylint output
************* Module test
test.py:3:6: E1126: Sequence index is not an int, slice, or instance with __index__ (invalid-sequence-index)
test.py:4:6: E1126: Sequence index is not an int, slice, or instance with __index__ (invalid-sequence-index)
Expected behavior
I would expect no error to be reported, since range.start
and range.stop
are integers and are perfectly valid for indexing a Sequence
(of appropriate length).
Pylint version
pylint 3.1.0
astroid 3.1.0
Python 3.11.8 | packaged by conda-forge | (main, Feb 16 2024, 20:49:36) [Clang 16.0.6 ]
OS / Environment
macOS Sonoma 14.5
Additional dependencies
No response