mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-30 22:01:47 +00:00
![]() ## Summary The initial purpose was to fix #15043, where code like this: ```python from fastapi import FastAPI, Query app = FastAPI() @app.get("/test") def handler(echo: str = Query("")): return echo ``` was being fixed to the invalid code below: ```python from typing import Annotated from fastapi import FastAPI, Query app = FastAPI() @app.get("/test") def handler(echo: Annotated[str, Query("")]): # changed return echo ``` As @MichaReiser pointed out, the correct fix is: ```python from typing import Annotated from fastapi import FastAPI, Query app = FastAPI() @app.get("/test") def handler(echo: Annotated[str, Query()] = ""): # changed return echo ``` After fixing the issue for `Query`, I realized that other classes like `Path`, `Body`, `Cookie`, `Header`, `File`, and `Form` also looked susceptible to this issue. The last few commits should handle these too, which I think means this will also close #12913. I had to reorder the arguments to the `do_stuff` test case because the new fix removes some default argument values (eg for `Path`: `some_path_param: str = Path()` becomes `some_path_param: Annotated[str, Path()]`). There's also #14484 related to this rule. I'm happy to take a stab at that here or in a follow up PR too. ## Test Plan `cargo test` I also checked the fixed output with `uv run --with fastapi FAST002_0.py`, but it required making a bunch of additional changes to the test file that I wasn't sure we wanted in this PR. --------- Co-authored-by: Micha Reiser <micha@reiser.io> |
||
---|---|---|
.. | ||
red_knot | ||
red_knot_python_semantic | ||
red_knot_server | ||
red_knot_test | ||
red_knot_vendored | ||
red_knot_wasm | ||
red_knot_workspace | ||
ruff | ||
ruff_benchmark | ||
ruff_cache | ||
ruff_db | ||
ruff_dev | ||
ruff_diagnostics | ||
ruff_formatter | ||
ruff_graph | ||
ruff_index | ||
ruff_linter | ||
ruff_macros | ||
ruff_notebook | ||
ruff_python_ast | ||
ruff_python_ast_integration_tests | ||
ruff_python_codegen | ||
ruff_python_formatter | ||
ruff_python_index | ||
ruff_python_literal | ||
ruff_python_parser | ||
ruff_python_resolver | ||
ruff_python_semantic | ||
ruff_python_stdlib | ||
ruff_python_trivia | ||
ruff_python_trivia_integration_tests | ||
ruff_server | ||
ruff_source_file | ||
ruff_text_size | ||
ruff_wasm | ||
ruff_workspace |