invalid-sequence-index / E1126ΒΆ
Message emitted:
Sequence index is not an int, slice, or instance with __index__
Description:
Used when a sequence type is indexed with an invalid type. Valid types are ints, slices, and objects with an __index__ method.
Problematic code:
fruits = ["apple", "banana", "orange"]
print(fruits["apple"]) # [invalid-sequence-index]
Correct code:
fruits = ["apple", "banana", "orange"]
print(fruits[0])
Additional details:
Be careful with [True]
or [False]
as sequence index, since True
and False
will respectively
be evaluated as 1
and 0
and will bring the second element of the list and the first without erroring.
Created by the typecheck checker.