Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions crates/ruff_linter/resources/test/fixtures/fastapi/FAST003.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,3 +256,12 @@ async def f4():
@app.get("/f5/{param: int}")
async def f5():
return locals()

# https://github.com/astral-sh/ruff/issues/20941
@app.get("/imports/{import}")
async def get_import():
...

@app.get("/debug/{__debug__}")
async def get_debug():
...
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use ruff_macros::{ViolationMetadata, derive_message_formats};
use ruff_python_ast as ast;
use ruff_python_ast::{Arguments, Expr, ExprCall, ExprSubscript, Parameter, ParameterWithDefault};
use ruff_python_semantic::{BindingKind, Modules, ScopeKind, SemanticModel};
use ruff_python_stdlib::identifiers::is_identifier;
use ruff_text_size::{Ranged, TextSize};

use crate::Fix;
Expand Down Expand Up @@ -191,7 +192,7 @@ pub(crate) fn fastapi_unused_path_parameter(
.add_start(TextSize::from(range.start as u32 + 1))
.sub_end(TextSize::from((path.len() - range.end + 1) as u32)),
);
if !is_positional {
if !is_positional && is_identifier(path_param) && path_param != "__debug__" {
diagnostic.set_fix(Fix::unsafe_edit(add_parameter(
path_param,
&function_def.parameters,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,3 +363,26 @@ help: Add `id` to function signature
206 |
207 | # No errors
note: This is an unsafe fix and may change runtime behavior

FAST003 Parameter `import` appears in route path, but not in `get_import` signature
--> FAST003.py:261:20
|
260 | # https://github.com/astral-sh/ruff/issues/20941
261 | @app.get("/imports/{import}")
| ^^^^^^^^
262 | async def get_import():
263 | ...
|
help: Add `import` to function signature

FAST003 Parameter `__debug__` appears in route path, but not in `get_debug` signature
--> FAST003.py:265:18
|
263 | ...
264 |
265 | @app.get("/debug/{__debug__}")
| ^^^^^^^^^^^
266 | async def get_debug():
267 | ...
|
help: Add `__debug__` to function signature