Pylint: used-before-assignment false positive with walrus operator inside if expression

Created on 14 Jan 2020  路  3Comments  路  Source: PyCQA/pylint

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)]
enhancement python 3.8

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.

All 3 comments

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?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lancelote picture lancelote  路  3Comments

DGalt picture DGalt  路  3Comments

DevynCJohnson picture DevynCJohnson  路  3Comments

PCManticore picture PCManticore  路  3Comments

Hubro picture Hubro  路  3Comments