Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Parenthesize breaking named expressions in match guards #9396

Merged
merged 3 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ def foo():
): # another comment
pass

case {
"long_long_long_key": str(long_long_long_key)
} if value := "long long long long long long long long long long long value":
pass


match pattern_comments:
case (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ use ruff_python_ast::AnyNodeRef;
use ruff_python_ast::ExprNamedExpr;

use crate::comments::{dangling_comments, SourceComment};
use crate::expression::parentheses::{NeedsParentheses, OptionalParentheses};
use crate::expression::parentheses::{
in_parentheses_only_soft_line_break_or_space, NeedsParentheses, OptionalParentheses,
};
use crate::prelude::*;

#[derive(Default)]
Expand All @@ -24,7 +26,10 @@ impl FormatNodeRule<ExprNamedExpr> for FormatExprNamedExpr {
write!(
f,
[
group(&format_args!(target.format(), soft_line_break_or_space())),
group(&format_args!(
target.format(),
in_parentheses_only_soft_line_break_or_space()
)),
charliermarsh marked this conversation as resolved.
Show resolved Hide resolved
token(":=")
]
)?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ match long_lines:
): # another comment
pass

case {
"long_long_long_key": str(long_long_long_key)
} if value := "long long long long long long long long long long long value":
pass


match pattern_comments:
case (
Expand Down Expand Up @@ -696,6 +701,11 @@ match long_lines:
): # another comment
pass

case {
"long_long_long_key": str(long_long_long_key)
} if value := "long long long long long long long long long long long value":
pass
charliermarsh marked this conversation as resolved.
Show resolved Hide resolved


match pattern_comments:
case (
Expand Down
Loading