using del in if clause confuses pyflakes

Bug #885140 reported by David
34
This bug affects 5 people
Affects Status Importance Assigned to Milestone
Pyflakes
Fix Released
Wishlist
Adi Roiban

Bug Description

code:

----------------------------------------
test = True
if False:
    del(test)
assert(test)
----------------------------------------

pyflakes complains:
[...].py:4: undefined name 'test'

i guess this may be too hard for a static analysier, in which case, how about

----------------------------------------
test = True
if False:
    del(test)
else:
    assert(test)
----------------------------------------

where the usage is in a different else branch to the del

output:
[...].py:5: undefined name 'test'

Revision history for this message
Jean-Paul Calderone (exarkun) wrote :

You're welcome to give it a try.

Changed in pyflakes:
assignee: nobody → David (david-szotten)
David (david-szotten)
Changed in pyflakes:
assignee: David (david-szotten) → nobody
Revision history for this message
Marcin Cieślak (saperski) wrote :

I have a code in https://github.com/kevinw/pyflakes/pull/28
(https://github.com/saper/pyflakes/commit/09c52fcfab742b4f67c9d21d18ae389c300b4ea6) to fix another bug https://bugs.launchpad.net/pyflakes/+bug/916264 but there is a code to detect if instructions are on different sides
of "if:" and "else:" or "try:/except:/else:". I think this approach could be applied to this case as well.

More info about how it works here:

https://code.launchpad.net/~dobey/divmod.org/pyflakes-less-redef/+merge/130183/comments/307409

Revision history for this message
Florent (florent.x) wrote :

bug #885140 marked as duplicate of this one

Changed in pyflakes:
importance: Undecided → Wishlist
Revision history for this message
Florent (florent.x) wrote :

bug #1212912, actually

Revision history for this message
Adi Roiban (adiroiban) wrote :

Here is my attempt to fix this https://github.com/pyflakes/pyflakes/pull/12

Please take a look. Thanks!

Changed in pyflakes:
status: New → In Progress
assignee: nobody → Adi Roiban (adiroiban)
Phil Frost (bitglue)
Changed in pyflakes:
status: In Progress → Fix Committed
Phil Frost (bitglue)
Changed in pyflakes:
status: Fix Committed → Fix Released
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.