Skip to content

F821 Undefined name when definition is after usage #119

Closed
@samuelcolvin

Description

@samuelcolvin

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions