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 inside if expression #3347

Closed
craigc40 opened this issue Jan 14, 2020 · 3 comments · Fixed by #4064
Closed

used-before-assignment false positive with walrus operator inside if expression #3347

craigc40 opened this issue Jan 14, 2020 · 3 comments · Fixed by #4064
Labels
Enhancement ✨ Improvement to a component python 3.8

Comments

@craigc40
Copy link

Steps to reproduce

  1. Save the following in a file
def func(): return None
s = 'foo' if (fval := func()) is None else fval
  1. run pylint on the script

Current behavior
Pylint returns

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

Expected behavior

No error (fval is assigned in the walrus assignment before being read)

pylint --version output

pylint 2.4.4
astroid 2.3.3
Python 3.8.1 (tags/v3.8.1:1b293b6, Dec 18 2019, 22:39:24) [MSC v.1916 32 bit (Intel)]
@AWhetter AWhetter added Enhancement ✨ Improvement to a component python 3.8 labels Jan 15, 2020
@craigc40
Copy link
Author

Hi @AWhetter, I was curious why this report wouldn't be categorized as a bug instead of as an enhancement. The walrus operator is already supported by pylint, so isn't it a bug for pylint to report used-before-assignment in this use case since the variable is actually being used?

@AWhetter
Copy link
Contributor

Bugs are when we have implemented something but it isn't working as intended.
pylint can parse the walrus operator but we haven't actually implemented support for it. It's a new feature.

codecakes referenced this issue in Xcov19/covidX Dec 1, 2020
@kootenpv
Copy link

Unless I am mistaken it means we should disable used-before-assignment for code that uses the walrus operator?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement ✨ Improvement to a component python 3.8
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants