E1126 invalid-sequence-index

Message

'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.

Pylint infers (guesses) the types of expressions in the analyzed code and checks whether the used types are valid for indexing.

Examples

In the following example we try to index a list by a, an object of type object().

def example():
    a = object()
    lst = [1]
    return lst[a]
4:11: E1126: Sequence index is not an int, slice, or instance with __index__

If the inference mechanism gets the type of an expression wrong or does not understand it, Pylint will emit warnings that are not justified.

Running Pylint locally? In your CI?

There is a better way! Run PyCodeQual & get Pylint findings with history, diffs and statistics.

Click here to find out more.