-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
References to names before they're bound should generate an error (UnboundLocalError) #686
Comments
I'm working on a solution for this issue in my 'scope' branch. |
Yup, mypy is currently too lenient, and catching these errors would be useful. This should still be fine and we shouldn't complain about this: def f(x: 'A'):
y = A()
class A: pass |
In Python 3.7, with Given that |
This is confusing for new users and they might not know about |
another example that foo() # runtime NameError: name 'foo' is not defined
def foo():
... |
Should we expect try:
raise ValueError
bar = 3
except Exception:
print(bar) Obviously this code actually produces |
@ilinum I think the original example in this issue should result in |
#14203 should fix this for classes and functions. |
Previously, we would ignore any class definitions and would fail to detect undefined classes and functions. This updates the logic to handle them. Closes #686
Connecting the dots: looks like #4019 tracks the local variable case. |
This code raises an error when executed but passes type checking:
The text was updated successfully, but these errors were encountered: