# Unused path parameter Path parameters are used to extract values from the URL path. If a path parameter is declared in the route path but not in the function signature, it will not be accessible in the function body, which is likely a mistake. If a path parameter is declared in the route path, but as a positional-only argument in the function signature, it will also not be accessible in the function body, as [[FastAPI]] will not inject the parameter. ```python # Don't @app.get("/things/{thing_id}") async def read_thing(query: str): ... # Do @app.get("/things/{thing_id}") async def read_thing(thing_id: int, query: str): ... ``` ## Automation This [[Anti-Patterns of Python|anti-pattern]] can be detected by [[Ruff]] (recommended): List of rules that can be automated by [[Ruff]]:[^1] | Code | Detected pattern | Name | | ------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------- | ------------------------------------ | | FAST003<br>⚠ This rule is unstable and in preview. The `--preview` flag is required for use.[^2] | `@app.get("/things/{thing_id}")`<br>`async def read_thing(query: str): …` | `fast-api-unused-path-parameter`[^3] | --- [^1]: [FastAPI (FAST) - docs.astral.sh](https://docs.astral.sh/ruff/rules/#fastapi-fast/) [^2]: [Preview - docs.astral.sh](https://docs.astral.sh/ruff/preview/) [^3]: [fast-api-unused-path-parameter (FAST003) - docs.astral.sh](https://docs.astral.sh/ruff/rules/fast-api-unused-path-parameter/)