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 false positive with walrus operator #4828

Closed
DetachHead opened this issue Aug 11, 2021 · 3 comments · Fixed by #4831
Closed

used-before-assignment false positive with walrus operator #4828

DetachHead opened this issue Aug 11, 2021 · 3 comments · Fixed by #4831
Assignees
Labels
Assignment expression Related to the walrus operator / assignment expression Bug 🪲 C: used-before-assignment Issues related to 'used-before-assignment' check False Positive 🦟 A message is emitted but nothing is wrong with the code python 3.8
Milestone

Comments

@DetachHead
Copy link
Contributor

DetachHead commented Aug 11, 2021

Bug description

used-before-assignment false positive occurs on the following code:

def foo() -> str:
    return bar if (bar := "") else ""

Configuration

No response

Command used

pylint foo.py

Pylint output

E0601: Using variable 'bar' before assignment (used-before-assignment)

Expected behavior

no error

Pylint version

pylint 2.9.6
astroid 2.6.6
Python 3.10.0b4 (v3.10.0b4:2ba4b20854, Jul  9 2021, 21:56:21) [Clang 12.0.5 (clang-1205.0.22.9)]

OS / Environment

No response

Additional dependencies

No response

@DetachHead DetachHead added Bug 🪲 Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Aug 11, 2021
@Pierre-Sassoulas Pierre-Sassoulas added False Positive 🦟 A message is emitted but nothing is wrong with the code python 3.8 and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Aug 12, 2021
@Pierre-Sassoulas
Copy link
Member

Thank you for opening the issue I can reproduce this.

@cdce8p cdce8p added the Assignment expression Related to the walrus operator / assignment expression label Aug 12, 2021
@cdce8p cdce8p self-assigned this Aug 12, 2021
@cdce8p cdce8p added this to the 2.10.0 milestone Aug 12, 2021
@0xallie
Copy link

0xallie commented Sep 4, 2022

I'm still seeing this in pylint 2.15.0:

"source": track.source if (track := first_or_none(self.tracks)) else "",
used-before-assignment: Using variable 'track' before assignment

@Pierre-Sassoulas
Copy link
Member

@nyuszika7h could you open another issue, please ? It look like it's affecting another node than a return in your case.

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 Bug 🪲 C: used-before-assignment Issues related to 'used-before-assignment' check False Positive 🦟 A message is emitted but nothing is wrong with the code python 3.8
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants