Skip to content

Strip form feeds from indent passed to dedent_to#24381

Merged
dylwil3 merged 3 commits intoastral-sh:mainfrom
dylwil3:form-feed-syntax
Apr 3, 2026
Merged

Strip form feeds from indent passed to dedent_to#24381
dylwil3 merged 3 commits intoastral-sh:mainfrom
dylwil3:form-feed-syntax

Conversation

@dylwil3
Copy link
Copy Markdown
Collaborator

@dylwil3 dylwil3 commented Apr 2, 2026

When adjusting "simple" indentation in the formation of edits, we attempt to dedent manually rather than deferring to LibCST. To do so we must provide a desired indentation, in the form of a string. We often grab this from source code by slicing the text in a range beginning at the start of a line.

In Python, the start of a line may contain form feeds but these do not contribute to the indentation. In this PR, we strip the provided indentation of its leading form feeds in order to get the correct indentation amount for use in dedent_to. This avoids the introduction of a syntax error in the edit adjust_indentation.

Note: We could try to stay closer to the user's intent by prepending the form feed prefix of the provided indentation everywhere in the resulting edit, but that seems a little unwieldy and this is a bit of an edge case anyway.

Closes #24373

@dylwil3 dylwil3 added bug Something isn't working fixes Related to suggested fixes for violations labels Apr 2, 2026
@astral-sh-bot
Copy link
Copy Markdown

astral-sh-bot bot commented Apr 2, 2026

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Formatter (stable)

✅ ecosystem check detected no format changes.

Formatter (preview)

✅ ecosystem check detected no format changes.

@dylwil3 dylwil3 merged commit 7fdb556 into astral-sh:main Apr 3, 2026
49 checks passed
carljm added a commit that referenced this pull request Apr 3, 2026
* main:
  Document adding fixes in CONTRIBUTING.md (#24393)
  Sort formatter diagnostics in snapshots (#24375)
  [`pyupgrade`] Fix panic caused by handling of octals in `UP012` (#24390)
  Upgrade to nix v0.31.2 (#24385)
  Strip form feeds from indent passed to `dedent_to` (#24381)
  add recent move of the `deferred` submodule to `.git-blame-ignore-revs` (#24379)
  [ty] Fix extra_items TypedDict tests (#24367)
  [ty] Use `infer_type_expression` for validating PEP-613 type aliases (#24370)
  [`flake8-simplify`] Make the fix for `collapsible-if` (`SIM102`) safe in `preview` (#24371)
  [ty] Validate TypedDict fields when subclassing (#24338)
  [ty] pass type context to sequence literals in binary operations (#24197)
  Add release environment to notify-dependents job (#24372)
  Bump 0.15.9 (#24369)
  [ty] Move the `deferred` submodule inside `infer/builder` (#24368)
  [ty] Infer the `extra_items` keyword argument to class-based TypedDicts as an annotation expression (#24362)
  [ty] Validate type qualifiers in functional TypedDict fields and the `extra_items` keyword to functional TypedDicts (#24360)
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.

Form feed before try makes the RUF072 fix introduce a syntax error

1 participant