invalid-index-returned / E0305ΒΆ

Message emitted:

__index__ does not return int

Description:

Used when an __index__ method returns something which is not an integer

Problematic code:

class CustomIndex:
    """__index__ returns a dict"""

    def __index__(self):  # [invalid-index-returned]
        return {"19": "19"}

Correct code:

class CustomIndex:
    """__index__ returns <type 'int'>"""

    def __index__(self):
        return 19

Created by the classes checker.