Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix formatting of single with-item with trailing comment #14005

Merged
merged 1 commit into from
Nov 1, 2024

Conversation

MichaReiser
Copy link
Member

@MichaReiser MichaReiser commented Oct 30, 2024

Summary

Fixes #14001

The root cause of the incorrect formatting is that is_expression_parenthesized returns true for with (expression) because it can't
determine that the parentheses belong to the with statement and not the expression.

The fix is to disregard whether the expression is parenthesized when the with statement is parenthesized and it's a single item.

Preview

We need to gate this behind preview because the formatter now removes the unnecessary parentheses

Test Plan

Added test

@MichaReiser MichaReiser added bug Something isn't working formatter Related to the formatter preview Related to preview mode features and removed bug Something isn't working labels Oct 30, 2024
@MichaReiser MichaReiser mentioned this pull request Oct 30, 2024
8 tasks
@MichaReiser MichaReiser force-pushed the micha/fix-single-with-trailing-comment branch from f8d5a2f to 4cf8b9e Compare October 30, 2024 18:27
@MichaReiser MichaReiser force-pushed the micha/fix-single-with-trailing-comment branch from 4cf8b9e to d132638 Compare October 30, 2024 18:32
Copy link
Contributor

ruff-ecosystem results

Formatter (stable)

✅ ecosystem check detected no format changes.

Formatter (preview)

✅ ecosystem check detected no format changes.

@lpulley
Copy link

lpulley commented Oct 30, 2024

How quick! Thanks! I see what you mean about this not being fun stuff to fix 😅

Copy link
Member

@dhruvmanila dhruvmanila left a comment

Choose a reason for hiding this comment

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

Seems reasonable

@MichaReiser MichaReiser merged commit cf0f5e1 into main Nov 1, 2024
20 checks passed
@MichaReiser MichaReiser deleted the micha/fix-single-with-trailing-comment branch November 1, 2024 08:08
TomerBin pushed a commit to TomerBin/ruff that referenced this pull request Nov 3, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
formatter Related to the formatter preview Related to preview mode features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Formatter can insert mysterious extraneous parentheses in with statements
3 participants