Skip to content

RUF029 triggers on FastAPI routes when they're inner functions #14903

@scy

Description

@scy

The following code triggers RUF029 (unused async):

from fastapi import FastAPI


def setup_app(app: FastAPI) -> None:
    @app.get("/")
    async def get_root() -> str:  # RUF029 here
        return "Hello World!"


app = FastAPI()


@app.get("/foo")
async def get_foo() -> str:  # no error
    return "Hello this is foo"

Note that it doesn't trigger on the top-level function.

That's because there is special handling in the code for FastAPI, implemented by @TomerBin in #12925/#12938, but I guess the underlying cause for the different outcome is that one of the is_fastapi_* checks in rules/fastapi/rules/mod.rs doesn't detect this case correctly.

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