Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pyflakes doesn't properly handle del inside function definition #428

Open
asmeurer opened this issue Feb 8, 2019 · 1 comment · May be fixed by #467
Open

Pyflakes doesn't properly handle del inside function definition #428

asmeurer opened this issue Feb 8, 2019 · 1 comment · May be fixed by #467

Comments

@asmeurer
Copy link
Contributor

asmeurer commented Feb 8, 2019

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").

@Hanaasagi
Copy link
Contributor

I'm working on it.

Hanaasagi added a commit to Hanaasagi/pyflakes that referenced this issue Sep 4, 2019
@Hanaasagi Hanaasagi linked a pull request Sep 4, 2019 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants