-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Open
Labels
help wantedContributions especially welcomeContributions especially welcomeruleImplementing or modifying a lint ruleImplementing or modifying a lint ruletype-inferenceRequires more advanced type inference.Requires more advanced type inference.
Description
Summary
I’ve noticed that the rule FAST003 (fast-api-unused-path-parameter) is reporting false positives when the path parameter is provided via a BaseModel using Depends.
For example, consider the following code:
from fastapi import APIRouter, Depends
from pydantic import BaseModel
from typing import Annotated
router = APIRouter()
class MyParams(BaseModel):
my_id: int
@router.get("/{my_id}")
async def get_id(params: Annotated[MyParams, Depends()]):
return {"my_id": params.my_id}In this case, my_id is being used correctly via the params dependency, but the linter still raises:
Parameter my_id appears in route path, but not in get_id signature Ruff [FAST003]
However, this is a valid and common FastAPI pattern, where parameters are parsed from Depends() into a Pydantic model.
Expected behavior
No warning should be raised when the path parameter is being handled inside a BaseModel via dependency injection.
Actual behavior
The linter raises FAST003 even though the parameter is properly used.
Additional notes
- This pattern is especially useful for grouping parameters together.
- The rule might need to inspect
Depends()models to detect path parameters coming from annotated dependencies.
Versions
Ruff: 0.11.3
FastAPI: 0.115.12
Pydantic: 2.11.2
Version
0.11.3
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
help wantedContributions especially welcomeContributions especially welcomeruleImplementing or modifying a lint ruleImplementing or modifying a lint ruletype-inferenceRequires more advanced type inference.Requires more advanced type inference.