pyflakes icon indicating copy to clipboard operation
pyflakes copied to clipboard

Pyflakes doesn't properly handle del inside function definition

Open asmeurer opened this issue 6 years ago • 1 comments

a = 1

def test():
    a = 2
    del a
    print(a)

test()

The code produces UnboundLocalError: local variable 'a' referenced before assignment, but pyflakes shows now errors.

The reason this code raises an exception is that local variables are determined statically at compile time, not at runtime, so the a = 2 line forces a to be function local inside of test. The del a does not make it global again (it is impossible to "make a local variable global again").

asmeurer avatar Feb 08 '19 23:02 asmeurer

I'm working on it.

Hanaasagi avatar Sep 04 '19 13:09 Hanaasagi