Skip to content

false positive E1137 with optional list #3832

Open
@ZeeD

Description

@ZeeD

I have this little module:

'xxx'

import typing

def main() -> None:
    'collapse rows if the first column is empty'

    rows: typing.Iterable[typing.List[str]] = [['foo', 'bar'], ['', 'baz']]

    itor = iter(rows)
    prev: typing.Optional[typing.List[str]] = None
    while True:
        try:
            row = next(itor)
        except StopIteration:
            break

        if row[0]:
            if prev is not None:
                print(prev)
            prev = row
        else:
            assert prev is not None

            for i, cell in enumerate(row):
                if i == 0:
                    continue

                prev[i] += ' ' + cell

    if prev is not None:
        print(prev)

if __name__ == '__main__':
    main()

while it does what I expect (it prints ['foo', 'bar baz']), pylint says that there is an error:

>pylint falsepositive.py
************* Module falsepositive
falsepositive.py:29:16: E1137: 'prev' does not support item assignment (unsupported-assignment-operation)

------------------------------------------------------------------
Your code has been rated at 7.83/10 (previous run: 7.83/10, +0.00)

pylint --version output

>pylint --version
pylint 2.6.0
astroid 2.4.2
Python 3.7.2 (tags/v3.7.2:9a3ffc0492, Dec 23 2018, 23:09:28) [MSC v.1916 64 bit (AMD64)]

Metadata

Metadata

Assignees

No one assigned

    Labels

    Control flowRequires control flow understandingEnhancement ✨Improvement to a componentNeeds PRThis issue is accepted, sufficiently specified and now needs an implementationtyping

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions