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

F821 "Undefined name" when variable is deleted in another branch #6242

Open
Louis-dM opened this issue Aug 1, 2023 · 1 comment
Open

F821 "Undefined name" when variable is deleted in another branch #6242

Louis-dM opened this issue Aug 1, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@Louis-dM
Copy link

Louis-dM commented Aug 1, 2023

Suppose I del a variable in an Exception branch:

def my_fn(a: str) -> str:
    try:
        print(a)
    except Exception:
        del a
        raise
    else:
        return a

a must always exist in the else branch, but Ruff claims it's undefined:

~$ ruff foobar.py --isolated
foobar.py:8:16: F821 Undefined name `a`
Found 1 error.

(line 8 char 16 is the location of the a in the return statement)

This is on version 0.0.281:

~$ ruff --version
ruff 0.0.281
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants