mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 02:38:25 +00:00
Parenthesize breaking named expressions in match guards (#9396)
## Summary This is an attempt to solve https://github.com/astral-sh/ruff/issues/9394 by avoiding breaks in named expressions when invalid.
This commit is contained in:
parent
b1a5df8694
commit
ba71772d93
3 changed files with 22 additions and 2 deletions
|
@ -109,6 +109,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 (
|
||||
|
|
|
@ -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)]
|
||||
|
@ -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()
|
||||
]),
|
||||
token(":=")
|
||||
]
|
||||
)?;
|
||||
|
|
|
@ -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 (
|
||||
|
@ -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
|
||||
|
||||
|
||||
match pattern_comments:
|
||||
case (
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue