-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
bugSomething isn't workingSomething isn't workingruleImplementing or modifying a lint ruleImplementing or modifying a lint rule
Description
Summary
It appears that using a Callable (defined as a class with a __call__ method) as a FastAPI dependency produces false positive FAST003 errors: path parameters that are declared in the __call__ method signature are not properly recognized.
This is demonstrated in the following example:
# main.py
from fastapi import FastAPI, Depends
from typing import Annotated
app = FastAPI()
class Query:
def __call__(self, id: str):
pass
@app.get("/things/{id}")
async def get(thing: Annotated[str, Depends(Query)]):
passFor which uv run ruff check main.py --select "FAST" --isolated produces:
FAST003 Parameter `id` appears in route path, but not in `get` signature
--> main.py:13:19
|
13 | @app.get("/things/{id}")
| ^^^^
14 | async def get(thing: Annotated[str, Depends(Query)]):
15 | pass
|
help: Add `id` to function signature
Found 1 error.
No fixes available (1 hidden fix can be enabled with the `--unsafe-fixes` option).By contrast, using a regular function as the dependency does not produce a false positive:
from fastapi import FastAPI, Depends
from typing import Annotated
app = FastAPI()
def query(id: str):
pass
@app.get("/things/{id}")
async def get(thing: Annotated[str, Depends(query)]):
passVersion
ruff 0.15.2
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingruleImplementing or modifying a lint ruleImplementing or modifying a lint rule