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

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

Closed
scy opened this issue Dec 10, 2024 · 1 comment · Fixed by #15093
Closed

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

scy opened this issue Dec 10, 2024 · 1 comment · Fixed by #15093
Labels
bug Something isn't working

Comments

@scy
Copy link

scy commented Dec 10, 2024

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.

scy added a commit to AKVorrat/dearmep that referenced this issue Dec 11, 2024
There is special handling in Ruff for FastAPI routes, but it's
apparently not recognizing this function as being one. I've opened
<astral-sh/ruff#14903> for it.

Signed-off-by: Tim Weber <[email protected]>
@TomerBin
Copy link
Contributor

Hi @scy
Thanks for pointing that out :)
A complete solution will depend on a proper type checking in ruff, but until it'll be landed I can improve the current logic to also detect fastapi routes whose app comes from a function typed argument.

Hopefully get into that in the following days :)

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.

3 participants