Skip to content

Conversation

@hengky-kurniawan-1
Copy link
Contributor

@hengky-kurniawan-1 hengky-kurniawan-1 commented Oct 11, 2025

Summary

Implement handling of ellipsis (...) defaults in the FAST002 autofix to correctly differentiate between required and optional parameters in FastAPI route definitions.

Previously, the autofix did not properly handle cases where parameters used ... as a default value (to indicate required parameters). This could lead to incorrect transformations when applying the autofix.

This change updates the FAST002 autofix logic to:

  • Correctly recognize ... as a valid FastAPI required default.
  • Preserve the semantics of required parameters while still applying other autofix improvements.
  • Avoid incorrectly substituting or removing ellipsis defaults.

Fixes #20800

Test Plan

Added a new test fixture at:
crates/ruff_linter/resources/test/fixtures/fastapi/FAST002_2.py

@ntBre ntBre added bug Something isn't working fixes Related to suggested fixes for violations labels Oct 15, 2025
Copy link
Contributor

@ntBre ntBre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! This looks great. I just had a couple of small ideas/suggestions about the tests.

@ntBre
Copy link
Contributor

ntBre commented Oct 15, 2025

It looks like the linux test failure was just a transient issue. The only real CI problem is the formatting.

@hengky-kurniawan-1
Copy link
Contributor Author

Thanks for the review! I’ll update it soon.

Copy link
Contributor

@ntBre ntBre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! We just need to update one more minor thing in the snapshots.

I tried to push a commit, but GitHub said I didn't have permission. Sorry for the trouble!

@ntBre ntBre enabled auto-merge (squash) October 21, 2025 02:43
@ntBre ntBre merged commit a802d7a into astral-sh:main Oct 21, 2025
36 checks passed
@github-actions
Copy link
Contributor

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

dcreager added a commit that referenced this pull request Oct 22, 2025
* main: (65 commits)
  [ty] Some more simplifications when rendering constraint sets (#21009)
  [ty] Make `attributes.md` mdtests faster (#21030)
  [ty] Set `INSTA_FORCE_PASS` and `INSTA_OUTPUT` environment variables from mdtest.py (#21029)
  [ty] Fall back to `Divergent` for deeply nested specializations (#20988)
  [`ruff`] Autogenerate TypeParam nodes (#21028)
  [ty] Add assertions to ensure that we never call `KnownClass::Tuple.to_instance()` or similar (#21027)
  [`ruff`] Auto generate ast Pattern nodes (#21024)
  [`flake8-simplify`] Skip `SIM911` when unknown arguments are present (#20697)
  Render a diagnostic for syntax errors introduced in formatter tests (#21021)
  [ty] Support goto-definition on vendored typeshed stubs (#21020)
  [ty] Implement go-to for binary and unary operators (#21001)
  [ty] Avoid ever-growing default types (#20991)
  [syntax-errors] Name is parameter and global (#20426)
  [ty] Disable panicking mdtest (#21016)
  [ty] Fix completions at end of file (#20993)
  [ty] Fix out-of-order semantic token for function with regular argument after kwargs (#21013)
  [ty] Fix auto import for files with `from __future__` import (#20987)
  [`fastapi`] Handle ellipsis defaults in FAST002 autofix (`FAST002`) (#20810)
  [`ruff`] Skip autofix for keyword and `__debug__` path params (#20960)
  [`flake8-bugbear`] Skip `B905` and `B912` if <2 iterables and no starred arguments (#20998)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working fixes Related to suggested fixes for violations

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FAST002 fix is invalid with ...

2 participants