Skip to content

unused-variable and undefined-variable with walrus operator #8425

@spagh-eddie

Description

@spagh-eddie

Bug description

The closest open issue I could find was #7538, but this has different error codes

Curiously, if I put the offending line outside of the decorator, there is no error

def decorate(x):
    def wrapped(f):
        print(x)
        return f()
    return wrapped

original = {"key": "value", "this": "that"}

@decorate((d := original.copy()) and d.pop("key") and d)  # pylint error
def g(): print("g")
% python test.py
{'this': 'that'}
g

Configuration

No response

Command used

pylint test.py --disable=C

Pylint output

************* Module test
t.py:9:37: E0602: Undefined variable 'd' (undefined-variable)
t.py:9:54: E0602: Undefined variable 'd' (undefined-variable)
t.py:9:11: W0612: Unused variable 'd' (unused-variable)

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

Expected behavior

no error

Pylint version

pylint 2.17.0
astroid 2.15.0
Python 3.10.5 (main, Jul 29 2022, 12:30:46) [Clang 13.0.0 (clang-1300.0.27.3)]

OS / Environment

% uname
Darwin

Additional dependencies

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions