Undefined variable defined later in a loop
Bug #1686327 reported by
asmeurer
This bug affects 1 person
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Pyflakes |
Won't Fix
|
Undecided
|
Unassigned |
Bug Description
For the following code
def test():
a = False
for i in range(10):
if a:
else:
a = True
b = 1
pyflakes gives the following errors
test.py:5: undefined name 'b'
test.py:8: local variable 'b' is assigned to but never used
But test() runs just fine without any errors.
To post a comment you must log in.
Here we know a is False because it was assigned with a literal. But what if it's the result of a function call, or even a more complex expression?
Have you encountered this in the wild?