Skip to content

[FAST003] False positive on Annotated dependency #21075

@vinnybod

Description

@vinnybod

Summary

A full reproduction can be seen at: https://github.com/vinnybod/reproductions/tree/vinnybod/FAST003

TL;DR:
If using thing=Depends(get_thing), the route path parameter thing_id is found in the get_thing dependency.
If using the equivalent thing: ThingDep, the route path parameter is considered missing by the FAST003 rule.

from typing import Annotated

from fastapi import FastAPI, Depends

app = FastAPI()


async def get_thing(thing_id: int):
    return {"thing_id": thing_id}


ThingDep = Annotated[dict, Depends(get_thing)]


# This is considered wrong by FAST003
@app.get("annotated/{thing_id}")
async def get_thing_endpoint(thing: ThingDep):
    return thing


# This is considered fine by FAST003
@app.get("depends/{thing_id}")
async def get_thing_endpoint(thing=Depends(get_thing)):
    return thing
> poetry run ruff check . --fix
FAST003 Parameter `thing_id` appears in route path, but not in `get_thing_endpoint` signature
  --> reproductions/main.py:16:21
   |
15 | # This is considered wrong by FAST003
16 | @app.get("annotated/{thing_id}")
   |                     ^^^^^^^^^^
17 | async def get_thing_endpoint(thing: ThingDep):
18 |     return thing
   |
help: Add `thing_id` to function signature

Found 1 error.
No fixes available (1 hidden fix can be enabled with the `--unsafe-fixes` option).

Version

ruff 0.14.1 (2bffef5 2025-10-16)

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs-decisionAwaiting a decision from a maintainerruleImplementing or modifying a lint rule

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions