Skip to content

used-before-assignment false positive on multiple-target assignment #5955

Open
@xmo-odoo

Description

@xmo-odoo

Bug description

When assigning to multiple target, and target n is used in target n+1, pylint flags the the line as E0601 "used-before-assignment", despite the statement being entirely correct per Python semantics:

# pylint: disable=missing-module-docstring, invalid-name
b = {}
a = b[id(a)] = 0

Even if there's an argument for flagging it (it's not great style), I don't think E0601 is valid.

Configuration

No response

Command used

`pylint <file>.py`

Pylint output

************* Module <file>
<file>.py:3:9: E0601: Using variable 'a' before assignment (used-before-assignment)

-----------------------------------------------------------------------
Your code has been rated at -15.00/10 (previous run: -25.00/10, +10.00)

Expected behavior

That the code passes, possibly triggers some sort of code style warning at most.

Pylint version

pylint 2.12.2
astroid 2.9.0
Python 3.8.12 (default, Sep 27 2021, 09:39:37)

OS / Environment

No response

Additional dependencies

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    C: used-before-assignmentIssues related to 'used-before-assignment' checkFalse Positive 🦟A message is emitted but nothing is wrong with the codeNeeds PRThis issue is accepted, sufficiently specified and now needs an implementation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions