Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

used-before-assignment when using walrus operator(:=) in dictionary with function #8486

Open
LCH-1 opened this issue Mar 23, 2023 · 0 comments
Labels
Assignment expression Related to the walrus operator / assignment expression C: used-before-assignment Issues related to 'used-before-assignment' check False Positive 🦟 A message is emitted but nothing is wrong with the code

Comments

@LCH-1
Copy link

LCH-1 commented Mar 23, 2023

Bug description

This issue is similar to #4828 and #8125, but seems to be different

The dictionary is fine when used alone, but when used with some function, the used-before-assignment code occurs.
Like issue #8425

test code

print({
    # used-before-assignment
    "key": test1 if (test1 := "var") else ""
})

dict({
    # used-before-assignment
    "key": test2 if (test2 := "var") else ""
})

{
    # normal
    "key": test3 if (test3 := "var") else ""
}

Configuration

No response

Command used

pylint test.py --disable=W0104,C0114

Pylint output

************* Module test
test.py:3:11: E0601: Using variable 'test1' before assignment (used-before-assignment)
test.py:8:11: E0601: Using variable 'test2' before assignment (used-before-assignment)

------------------------------------------------------------------
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.1
astroid 2.15.0
Python 3.11.1

OS / Environment

No response

Additional dependencies

No response

@LCH-1 LCH-1 added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Mar 23, 2023
@nickdrozd nickdrozd added False Positive 🦟 A message is emitted but nothing is wrong with the code Assignment expression Related to the walrus operator / assignment expression and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Mar 24, 2023
@jacobtylerwalls jacobtylerwalls added the C: used-before-assignment Issues related to 'used-before-assignment' check label Mar 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Assignment expression Related to the walrus operator / assignment expression C: used-before-assignment Issues related to 'used-before-assignment' check False Positive 🦟 A message is emitted but nothing is wrong with the code
Projects
None yet
Development

No branches or pull requests

3 participants