Skip to content

Parenthesize breaking named expressions in match guards#9396

Merged
charliermarsh merged 3 commits intomainfrom
charlie/parens
Jan 8, 2024
Merged

Parenthesize breaking named expressions in match guards#9396
charliermarsh merged 3 commits intomainfrom
charlie/parens

Conversation

@charliermarsh
Copy link
Copy Markdown
Member

@charliermarsh charliermarsh commented Jan 5, 2024

Summary

This is an attempt to solve #9394 by avoiding breaks in named expressions when invalid.

Comment thread crates/ruff_python_formatter/tests/snapshots/format@statement__match.py.snap Outdated
@charliermarsh charliermarsh added bug Something isn't working formatter Related to the formatter labels Jan 5, 2024
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Jan 5, 2024

ruff-ecosystem results

Formatter (stable)

✅ ecosystem check detected no format changes.

Formatter (preview)

✅ ecosystem check detected no format changes.

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.

I feel the same as you. Maybe parenthesze is mainly intended to use for top level expressions, not for nested sub expressions.

I haven't looked at the issue (on my phone) but this is probably something that needs solving in the case formatting or we should use in_parentheses_only_softline_break in the if expression formatting

@charliermarsh
Copy link
Copy Markdown
Member Author

Let me try in_parentheses_only_softline_break, that's interesting.

@charliermarsh charliermarsh marked this pull request as ready for review January 5, 2024 02:12
@charliermarsh
Copy link
Copy Markdown
Member Author

Ok this now looks right...

@zanieb
Copy link
Copy Markdown
Member

zanieb commented Jan 5, 2024

Nice!

Comment thread crates/ruff_python_formatter/src/expression/expr_named_expr.rs Outdated
@MichaReiser
Copy link
Copy Markdown
Member

Thank you

Co-authored-by: Micha Reiser <micha@reiser.io>
@charliermarsh charliermarsh enabled auto-merge (squash) January 8, 2024 14:41
@charliermarsh charliermarsh merged commit ba71772 into main Jan 8, 2024
@charliermarsh charliermarsh deleted the charlie/parens branch January 8, 2024 14:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working formatter Related to the formatter

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants