Skip to content

RUF010: Mark fix as unsafe when it deletes a comment#24270

Merged
MichaReiser merged 6 commits intoastral-sh:mainfrom
tranhoangtu-it:fix/ruf010-unsafe-when-comment-deleted
Mar 31, 2026
Merged

RUF010: Mark fix as unsafe when it deletes a comment#24270
MichaReiser merged 6 commits intoastral-sh:mainfrom
tranhoangtu-it:fix/ruf010-unsafe-when-comment-deleted

Conversation

@tranhoangtu-it
Copy link
Copy Markdown
Contributor

Fixes #19745

Copilot AI review requested due to automatic review settings March 28, 2026 16:16
@astral-sh-bot astral-sh-bot bot requested a review from amyreese March 28, 2026 16:17
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates RUF010’s autofix logic so the fix is marked unsafe when applying it would delete comments inside the original call expression (addressing #19745).

Changes:

  • Compute fix applicability for RUF010 by detecting comments that would be removed when rewriting str/repr/ascii calls to f-string conversion flags.
  • Use parenthesized_range to treat comments inside extra parentheses around the argument as preserved (keeping the fix safe in those cases).
  • Add fixture coverage for “comment deleted ⇒ unsafe” and “comment preserved ⇒ safe” scenarios.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
crates/ruff_linter/src/rules/ruff/rules/explicit_f_string_type_conversion.rs Marks the fix unsafe when it would delete comments outside the preserved (parenthesized) argument range.
crates/ruff_linter/resources/test/fixtures/ruff/RUF010.py Adds fixture cases intended to validate unsafe vs safe fix applicability around comments.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0646d9b6ad

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Copy link
Copy Markdown
Member

@MichaReiser MichaReiser left a comment

Choose a reason for hiding this comment

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

Thanks for working on this.

Can you take a look at the failing CI jobs and change the test as I suggested in the inline comment.

@MichaReiser MichaReiser added the fixes Related to suggested fixes for violations label Mar 30, 2026
@astral-sh-bot
Copy link
Copy Markdown

astral-sh-bot bot commented Mar 30, 2026

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Wraps the `def ascii(arg): pass` shadow and its test case into
a `def ascii_shadowing():` nested function so it doesn't shadow
the builtin `ascii` for the new test cases below.
@tranhoangtu-it
Copy link
Copy Markdown
Contributor Author

Done! Moved def ascii into a nested def ascii_shadowing(): scope so it no longer shadows the builtin ascii for the test cases below. The line count stays the same so snapshots should be unaffected. Waiting for CI to confirm.

@MichaReiser MichaReiser enabled auto-merge (squash) March 31, 2026 14:55
@MichaReiser MichaReiser disabled auto-merge March 31, 2026 14:55
@MichaReiser MichaReiser changed the title Mark RUF010 fix as unsafe when it deletes a comment RUF010: Mark fix as unsafe when it deletes a comment Mar 31, 2026
@MichaReiser MichaReiser enabled auto-merge (squash) March 31, 2026 14:55
@MichaReiser MichaReiser merged commit 40181e8 into astral-sh:main Mar 31, 2026
41 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fixes Related to suggested fixes for violations

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RUF010 fix should be unsafe when it deletes a comment

4 participants