undefined-variable or used-before-assignment should be reported when variable is declared with a type annotation but not assigned to before use #5140
Labels
False Negative 🦋
No message is emitted but something is wrong with the code
Milestone
Bug description
Pylint does not report an error for the code above.
This code:
produces:
uninitialized_variable_test.py:2:6: E0602: Undefined variable 'x' (undefined-variable)
This code:
produces:
uninitialized_variable_test.py:1:0: W0104: Statement seems to have no effect (pointless-statement)
uninitialized_variable_test.py:1:0: E0602: Undefined variable 'x' (undefined-variable)
uninitialized_variable_test.py:2:6: E0602: Undefined variable 'x' (undefined-variable)
This code:
produces no error.
This code:
produces:
uninitialized_variable_test.py:2:6: E0601: Using variable 'x' before assignment (used-before-assignment)
Python produces a runtime error for all three cases:
NameError: name 'x' is not defined
(FYI, Mypy and pytype also do not catch this error.)
Pylint output
Expected behavior
Should get an undefined variable error in the same cases in which one would get the error without the variable having been declared but not assigned, OR it should produce a used-before-assignment error.
Pylint version
OS / Environment
Ubuntu 16.04
Additional dependencies
No response
The text was updated successfully, but these errors were encountered: