Steps to reproduce
def func(): return None
s = 'foo' if (fval := func()) is None else fval
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)]
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?
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.
Unless I am mistaken it means we should disable used-before-assignment for code that uses the walrus operator?
Most helpful comment
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.