False positive undefined name, which is defined in branch
Bug #1612066 reported by
afg984
This bug affects 1 person
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Pyflakes |
New
|
Undecided
|
Unassigned |
Bug Description
this code gives: undefined name 'j'
for i in range(10):
if i % 3 == 0:
j += i
else:
j = 0
print(j)
while the following emits nothing
for i in range(10):
if not i % 3 == 0:
j = 0
else:
j += i
print(j)
pyflakes --version
1.2.3
I'm creating a new report besides #1431099 and #1308508 because this is not related to the del statement
Pyflakes ignores conditional branches, since short of being a Python interpreter it can't really know if they will branch or not. So all pyflakes sees is this:
j += 1
j = 0
print(j)
j = 0
j += 1
print(j)
Can you think of a way to handle this situation which doesn't involve running the code, and which does not generate false positives?