Closed
Description
Bug description
def func():
try:
print(value for value in range(1 / 0) if isinstance(value, int)) # BUG: emits used-before-assignment
except ZeroDivisionError:
value = 1
Configuration
No response
Command used
pylint a.py
Pylint output
************* Module a
/Users/.../a.py:3:60: E0601: Using variable 'value' before assignment (used-before-assignment)
Expected behavior
No message.
Here, found_nodes
for the node inside the generator expression includes the assignment of value
in the except block.
https://github.com/PyCQA/pylint/blob/c0fbbb7adbc39cbd67bbd0e0b1ca4e9421c12643/pylint/checkers/variables.py#L611-L620
I'm not sure if the responsibility for filtering that out lies in to_consume()
; if not, I suppose the new used-before-assignment
logic will have to deal with it.
Pylint version
Caused in bd55b27d41542e3ca1f031f986b6151f6cac457f (2.13.0 unreleased)
OS / Environment
No response
Additional dependencies
No response