Skip to content

Bad unsubscriptable-object error #2016

@nickdrozd

Description

@nickdrozd

Steps to reproduce

def subscriptable(flag):
    state = None
    for _ in [0, 1]:
        if state is None:
            if flag:
                state = [None]
        elif state[0] is None:
            print('subscripted')

Current behavior

E: 7,13: Value 'state' is unsubscriptable (unsubscriptable-object)

Expected behavior

state is subscriptable by the time it gets subscripted, so that
error is wrong. After all, the code runs:

>>> subscriptable(False)
>>> subscriptable(True)
subscripted

That said, it does look like it could be an error, or maybe it would
be an error in a more complicated case, so maybe a warning could be
emitted -- possibly-unsubscriptable-object or something like that.

Related to, but more specific than, #701

pylint --version output

pylint 2.0.0
astroid 2.0.0
Python 3.6.5 (default, Mar 30 2018, 06:42:10) 
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2)]

Metadata

Metadata

Assignees

No one assigned

    Labels

    Control flowRequires control flow understandingMinor 💅Polishing pylint is always nice

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions