# Non-annotated dependency The [[FastAPI]] documentation[^1] recommends the use of `typing.Annotated` for defining route dependencies and [[Parameter|parameters]], rather than using `fastapi.Depends`, `fastapi.Query` or similar as default value for a [[parameter]]. ```python # Don't @app.get("/items/") async def read_items(commons: dict = fastapi.Depends(common_parameters)): return commons # Do @app.get("/items/") async def read_items(commons: typing.Annotated[dict, fastapi.Depends(commun_parameters)]): return commons ``` ## Backwards compatibility `typing.Annotated` was added to the `typing` module in [[Python 3.9]]; however, the third-party [[typing-extension]] [[package]] provides a backport that can be used on older versions of [[Python]]. ```python # Python < 3.9 import typing_extensions @app.get("/items/") async def read_items(commons: typing_extensions.Annotated[dict, fastapi.Depends(commun_parameters)]): return commons ``` ## Automation This [[Anti-Patterns of Python|anti-pattern]] can be detected by [[Ruff]] (recommended) : List of rules that can be automated by [[Ruff]]:[^2] | Code | Detected pattern | Name | | ------- | --------------------------------------------------------------------------- | --------------------------------------- | | FAST002 | `async def read_items(commons: dict = fastapi.Depends(common_parameters)):` | `fast-api-non-annotated-dependency`[^3] | --- [^1]: [FastAPI Response Model / Return Type - fastapi.tiangolo.com](https://fastapi.tiangolo.com/tutorial/response-model/) [^2]: [FastAPI (FAST) - docs.astral.sh](https://docs.astral.sh/ruff/rules/#fastapi-fast/) [^3]: [fast-api-non-annotated-dependency (FAST002) - docs.astral.sh](https://docs.astral.sh/ruff/rules/fast-api-non-annotated-dependency/)