pyflakes gives erroneous 'undefined name'

Bug #1431099 reported by John L. Villalovos
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Pyflakes
Confirmed
Medium
Unassigned

Bug Description

$ cat tt.py
#!/usr/bin/python -tt
import random
import sys

def main():
    f = None
    try:
        f = "bob"
        if random.choice((True, False)):
            raise Exception('test')
    except:
        del f
        raise Exception('my custom exception')
    print f

if '__main__' == __name__:
    sys.exit(main())

$ $ pyflakes tt.py
tt.py:15: undefined name 'f'

summary: - pyflakes gives erroneous F821
+ pyflakes gives erroneous 'undefined name'
description: updated
Revision history for this message
Phil Frost (bitglue) wrote :

Confirmed. Thanks for the report.

Changed in pyflakes:
status: New → Confirmed
importance: Undecided → Medium
Revision history for this message
Peuchele (peuchele) wrote :

I was about to report the same issue, but with a different example. Pasting here for reference:
x = 0
while True:
    data = "dummy"
    if x == 1:
        del data
        break
    print data
    del data
    break

Real life example:
https://github.com/jelmer/dulwich/blob/master/dulwich/protocol.py#L353

Revision history for this message
John Vandenberg (jayvdb) wrote :

I believe these are both the same problem as https://bugs.launchpad.net/pyflakes/+bug/1308508 .

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.