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 definition is after usage #119

Closed
samuelcolvin opened this issue Sep 7, 2022 · 2 comments · Fixed by #125
Closed

F821 Undefined name when definition is after usage #119

samuelcolvin opened this issue Sep 7, 2022 · 2 comments · Fixed by #125
Labels
bug Something isn't working

Comments

@samuelcolvin
Copy link

Ruff looks great, congratulations. I'd love to use it one day on pydantic instead of flake8.


The following code is valid python and runs fine

def main():
    foo()

def foo():
    print('this is foo')

main()

However ruff returns:

test.py:2:5: F821 Undefined name `foo`

Found 1 error(s).

Running ruff on pydantic's code base is currently returning 151 F821 errors, so it's a fairly common problem.

@charliermarsh
Copy link
Member

Thank you! Really flattered by the interest.

This is a legit bug. We have to defer checking function scopes until we've parsed the rest of the module. It's known but unhandled. Gonna use this issue for tracking.

@samuelcolvin
Copy link
Author

great, thanks so much.

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

Successfully merging a pull request may close this issue.

2 participants