-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Open
Labels
Assignment expressionRelated to the walrus operator / assignment expressionRelated to the walrus operator / assignment expressionC: undefined-variableIssues related to 'undefined-variable' checkIssues related to 'undefined-variable' checkFalse Negative 🦋No message is emitted but something is wrong with the codeNo message is emitted but something is wrong with the codeNeeds PRThis issue is accepted, sufficiently specified and now needs an implementationThis issue is accepted, sufficiently specified and now needs an implementation
Description
Current problem
import random
enter_first = True
while enter_first or (some_walrus := random.random()) < 0.9:
print(some_walrus)
enter_first = False
This code will fail, because enter_first
short circuits, and the variable some_walrus
isn't set.
Traceback (most recent call last):
File "/path/to/a.py", line 5, in <module>
print(some_walrus)
NameError: name 'some_walrus' is not defined
Desired solution
It would be pretty cool if pylint
could flag this vulnerabiltity. Basically, the idea is warning if a short circuit can lead to a local variable not being present.
Additional context
No response
Pierre-Sassoulas
Metadata
Metadata
Assignees
Labels
Assignment expressionRelated to the walrus operator / assignment expressionRelated to the walrus operator / assignment expressionC: undefined-variableIssues related to 'undefined-variable' checkIssues related to 'undefined-variable' checkFalse Negative 🦋No message is emitted but something is wrong with the codeNo message is emitted but something is wrong with the codeNeeds PRThis issue is accepted, sufficiently specified and now needs an implementationThis issue is accepted, sufficiently specified and now needs an implementation