-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
False positive used-before-assignment
for type annotations that take assignment via nonlocal
#5394
Comments
This is a regression in pylint 2.12. Probably caused by #5158. |
This might be difficult to solve as it requires control-flow knowledge. We can't do a simple check for a definition in an inner function as then this wouldn't be catched: def f():
x: int
def g():
nonlocal x
x = 5
print(x) # x is undefined
g()
f() For now I would advise to add an disable to this line. Sorry about that! |
I understand that it's undecidable in the general case. You could, however, err on the side of avoiding false positives by only emitting this error if the variable is not assigned in any scope. |
I don't remember the code by heart but I'll have a look in the near future. I'm not sure whether that approach would greatly increase the amount of false negatives, but I/we can at least try. If somebody else would like to have a look before me, please go ahead! |
On 2.13.x this emits |
undefined-variable
when the variable is initialized in a nested scopeused-before-assignment
when the variable is initialized in a nested scope
used-before-assignment
when the variable is initialized in a nested scopeused-before-assignment
for type annotations that take assignment via nonlocal
Bug description
Create
test.py
with the following content:Configuration
No response
Command used
Pylint output
Expected behavior
There should be no errors reported.
Pylint version
OS / Environment
No response
Additional dependencies
No response
The text was updated successfully, but these errors were encountered: