"Dead code" after a return

Bug #1274566 reported by asmeurer
12
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Pyflakes
New
Wishlist
Unassigned

Bug Description

Is there a reason pyflakes doesn't warn on "dead code", i.e., code that cannot possibly be run because it comes after a return or a raise in the same block, like

def f():
    return
    g() # cannot be reached

I think return, raise, break, and continue are all such statements.

In a similar vein (should this be a separate issue?), what about unnecessary pass, like

if x:
    pass
    f()

Inline non-string literals or bare variable names might also fit into this category, although the latter can be a useful way to squash incorrect "unused variable" warnings.

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

Also assignments preceding a return/raise, but not used in that branch.

def foo(a):
    if a:
        x = 10
        return a
    else:
        x = 20

    return x

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.