You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using a "undefined" variable, which will immediately crash the code when running it, mypy does not report anything about it. Is it normal ?
I feel like mypy should report it but maybe I am wrong because this isn't a typing error. On the other hand, this error is only possible because typing annotations exist . What do you think ?
main.py:2: error: Using an undefined variable, a value must be set before first. [var-undefined]
Actual Behavior
$ mypy --strict main.py
Success: no issues found in 1 source file
python main.py
Traceback (most recent call last):
File "/home/user/main.py", line 2, in <module>
print(number)
^^^^^^
NameError: name 'number' is not defined
Your Environment
Mypy version used: 1.3.0
Mypy command-line flags: --strict
Mypy configuration options from mypy.ini (and other config files): nothing
Python version used: 3.11.3
The text was updated successfully, but these errors were encountered:
From mypy's perspective, "uninitialized" or "unassigned" probably described it better than "undefined". Maybe change the title to "Not reporting uninitialized variable read"?
This seems related to #4019 but not quite the same (at first glance, #4019 seems much more complicated, since a declared class attribute might or might not be initialized elsewhere).
Bug Report
When using a "undefined" variable, which will immediately crash the code when running it, mypy does not report anything about it. Is it normal ?
I feel like mypy should report it but maybe I am wrong because this isn't a typing error. On the other hand, this error is only possible because typing annotations exist . What do you think ?
To Reproduce
Dump this in a file
main.py
:Gist URL: https://gist.github.com/mypy-play/31d3775229a6fe01af6bbb09b9230a18
Playground URL: https://mypy-play.net/?mypy=latest&python=3.11&gist=31d3775229a6fe01af6bbb09b9230a18
Expected Behavior
An error message, maybe something like this.
Actual Behavior
Your Environment
mypy.ini
(and other config files): nothingThe text was updated successfully, but these errors were encountered: