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 when walrus / assignment expression assigned and used in same expression #3953

Closed
OJFord opened this issue Nov 23, 2020 · 2 comments · Fixed by #4064
Labels
Assignment expression Related to the walrus operator / assignment expression Bug 🪲 False Positive 🦟 A message is emitted but nothing is wrong with the code

Comments

@OJFord
Copy link

OJFord commented Nov 23, 2020

Similar to #3249

Steps to reproduce

  1. assert (n := len(stuff)) == 123, f"Expected length 123, but got {n}"
  2. pylint

Current behavior

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

Expected behavior

Pass.

pylint --version output

v2.6.0

@OJFord
Copy link
Author

OJFord commented Nov 24, 2020

Another example (not using assert):

dict({"options": (d := json.loads(data))}, data=d["data"])

@OJFord OJFord changed the title used-before-assignment false positive with assert walrus / assignment expression, using assigned var used in second arg used-before-assignment false positive with walrus / assignment expression assigned and used in fn arguments Nov 24, 2020
@OJFord
Copy link
Author

OJFord commented Nov 26, 2020

Also in ternaries, e.g.:

foo = m.group("foo") if (m := FOO_PATT.match(bar)) else "bar"

@OJFord OJFord changed the title used-before-assignment false positive with walrus / assignment expression assigned and used in fn arguments used-before-assignment false positive when walrus / assignment expression assigned and used in same expression Nov 26, 2020
@hippo91 hippo91 added Bug 🪲 False Positive 🦟 A message is emitted but nothing is wrong with the code Assignment expression Related to the walrus operator / assignment expression labels Dec 1, 2020
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 🪲 False Positive 🦟 A message is emitted but nothing is wrong with the code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants