-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Incorrect Undefined Variable for Outer Scope Var #1908
Comments
That error is correct. The code will throw an UnboundLocalError at runtime. To fix it, you need to write |
That code is simplified part of a unit test that runs successfully. Also the error message goes away if I tweak to from typing import Callable, Optional
even though that code starts the exact same way. |
That code is very different, because it creates a separate variable |
Testing that, that does explain the error.A bit surprised that even though the two examples start the same, the later mutation in first breaks the first access. Reading the nonlocal documentation explains it. |
Made completion provider to use newly added getExpectedType + Test
Describe the bug
Variable marked as undefined when coming from an outer scope and then assigned in one branch.
To Reproduce
Error message, "x" is not defined for the line
if not x
Expected behavior
No error.
VS Code extension or command-line
pylance 2021.5.4-pre.1
The text was updated successfully, but these errors were encountered: