-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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 gives false positives with FastApi routes #12925
Comments
That sounds reasonable. The only concern is that we start to have a lot of framework specific code. Something we generally try to avoid. @AlexWaygood any opinion on that? |
Yeah, I'm a little wary of adding special-casing for third-party libraries to generalised rules like I'm also not sure how we'd actually address the false positive here. It would require quite sophisticated semantic analysis (including some attempt at type inference), which wouldn't necessarily be accurate without multifile analysis. IIUC, the false positive is emitted on code like this: from fastapi import FastAPI
app = FastAPI()
@app.get('/')
async def read_results(): # RUF029
return foo() To get rid of this false positive, we'd have to:
It would be possible, but it would be complicated, and would require encoding a lot of knowledge about fastAPI internals into the rule. I'm not sure if it would be worth it, personally. Possibly the best course of action would be to add a "Known limitations" section to the |
I think we already have an |
Ah, nice. That resolves my concern about the added complexity. Given that we already have this logic implemented, and given that I can't really see any other way of addressing the false positive (you couldn't really add a configuration option here), I suppose we may as well use it to get rid of the false positive in RUF029, then. |
I would like to suggest that RUF029 will skip functions that are FastApi routes. In their docs, it is explicitly mentioned that sometimes routes should be declared as async function, even when not doing any asynchronous operation.
As a first step we can introduce a new rule setting that will allow opting into this new behavior.
One caveat is with FastApi dependencies that we should handle the same way but we can't since dependencies are just native functions and can't be detected in their deceleration (only in usage), but I believe that ignoring routes and keeping the current behavior for dependencies is a good step.
If you find this reasonable, I would like to implement it 😊
The text was updated successfully, but these errors were encountered: