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
If the above program is ran without NAME set, it'll crash:
$ NAME='Jeff' python reference_before_assign.py
Hello, Jeff.
$ python reference_before_assign.py
Traceback (most recent call last):
File "/Users/jeff.rabovsky/git_repos/notes/reference_before_assign.py", line 17, in <module>
main()
File "/Users/jeff.rabovsky/git_repos/notes/reference_before_assign.py", line 13, in main
greet(os.environ.get("NAME"))
File "/Users/jeff.rabovsky/git_repos/notes/reference_before_assign.py", line 9, in greet
print(f"Hello{name_str}")
UnboundLocalError: local variable 'name_str' referenced before assignment
My expectation was that mypy would catch this error.
Actual Behavior
$ mypy --strict reference_before_assign.py
Success: no issues found in 1 source file
Your Environment
Mypy version used: 0.982
Mypy command-line flags: --strict
Mypy configuration options from mypy.ini (and other config files): none
Python version used: 3.10.5
Thanks for your help!
The text was updated successfully, but these errors were encountered:
Bug Report
mypy doesn't catch "reference before assignment" errors
To Reproduce
Expected Behavior
If the above program is ran without
NAME
set, it'll crash:My expectation was that mypy would catch this error.
Actual Behavior
Your Environment
0.982
--strict
mypy.ini
(and other config files): noneThanks for your help!
The text was updated successfully, but these errors were encountered: