mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-26 11:59:10 +00:00
Add new with
and match
sequence test cases (#9128)
## Summary Add new test cases for `with_item` and `match` sequence that demonstrate how long headers break. Removes one use of `optional_parentheses` in a position where it is know that the parentheses always need to be added. ## Test Plan cargo test
This commit is contained in:
parent
25b2361411
commit
c8d6958d15
5 changed files with 34 additions and 5 deletions
|
@ -578,3 +578,8 @@ match n % 3, n % 5:
|
||||||
print("Buzz")
|
print("Buzz")
|
||||||
case _:
|
case _:
|
||||||
print(n)
|
print(n)
|
||||||
|
|
||||||
|
# Unparenthesized tuples
|
||||||
|
match x:
|
||||||
|
case Child(aaaaaaaaa, bbbbbbbbbbbbbbb, cccccc), Doc(aaaaa, bbbbbbbbbb, ddddddddddddd):
|
||||||
|
pass
|
||||||
|
|
|
@ -303,3 +303,7 @@ if True:
|
||||||
if True:
|
if True:
|
||||||
with anyio.CancelScope(shield=True) if get_running_loop() else contextlib.nullcontext():
|
with anyio.CancelScope(shield=True) if get_running_loop() else contextlib.nullcontext():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
with Child(aaaaaaaaa, bbbbbbbbbbbbbbb, cccccc), Document(aaaaa, bbbbbbbbbb, ddddddddddddd):
|
||||||
|
pass
|
||||||
|
|
|
@ -6,9 +6,7 @@ use ruff_text_size::{Ranged, TextRange};
|
||||||
|
|
||||||
use crate::builders::parenthesize_if_expands;
|
use crate::builders::parenthesize_if_expands;
|
||||||
use crate::comments::SourceComment;
|
use crate::comments::SourceComment;
|
||||||
use crate::expression::parentheses::{
|
use crate::expression::parentheses::parenthesized;
|
||||||
in_parentheses_only_soft_line_break_or_space, optional_parentheses, parenthesized,
|
|
||||||
};
|
|
||||||
use crate::other::commas;
|
use crate::other::commas;
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use crate::statement::clause::{clause_body, clause_header, ClauseHeader};
|
use crate::statement::clause::{clause_body, clause_header, ClauseHeader};
|
||||||
|
@ -77,7 +75,7 @@ impl FormatNodeRule<StmtWith> for FormatStmtWith {
|
||||||
joiner.entry_with_line_separator(
|
joiner.entry_with_line_separator(
|
||||||
item,
|
item,
|
||||||
&item.format(),
|
&item.format(),
|
||||||
in_parentheses_only_soft_line_break_or_space(),
|
soft_line_break_or_space(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
joiner.finish()
|
joiner.finish()
|
||||||
|
@ -87,7 +85,7 @@ impl FormatNodeRule<StmtWith> for FormatStmtWith {
|
||||||
// This is similar to `maybe_parenthesize_expression`, but we're not
|
// This is similar to `maybe_parenthesize_expression`, but we're not
|
||||||
// dealing with an expression here, it's a `WithItem`.
|
// dealing with an expression here, it's a `WithItem`.
|
||||||
if comments.has_leading(item) || comments.has_trailing(item) {
|
if comments.has_leading(item) || comments.has_trailing(item) {
|
||||||
optional_parentheses(&item.format()).fmt(f)?;
|
parenthesized("(", &item.format(), ")").fmt(f)?;
|
||||||
} else {
|
} else {
|
||||||
item.format().fmt(f)?;
|
item.format().fmt(f)?;
|
||||||
}
|
}
|
||||||
|
|
|
@ -584,6 +584,11 @@ match n % 3, n % 5:
|
||||||
print("Buzz")
|
print("Buzz")
|
||||||
case _:
|
case _:
|
||||||
print(n)
|
print(n)
|
||||||
|
|
||||||
|
# Unparenthesized tuples
|
||||||
|
match x:
|
||||||
|
case Child(aaaaaaaaa, bbbbbbbbbbbbbbb, cccccc), Doc(aaaaa, bbbbbbbbbb, ddddddddddddd):
|
||||||
|
pass
|
||||||
```
|
```
|
||||||
|
|
||||||
## Output
|
## Output
|
||||||
|
@ -1210,6 +1215,13 @@ match n % 3, n % 5:
|
||||||
print("Buzz")
|
print("Buzz")
|
||||||
case _:
|
case _:
|
||||||
print(n)
|
print(n)
|
||||||
|
|
||||||
|
# Unparenthesized tuples
|
||||||
|
match x:
|
||||||
|
case Child(aaaaaaaaa, bbbbbbbbbbbbbbb, cccccc), Doc(
|
||||||
|
aaaaa, bbbbbbbbbb, ddddddddddddd
|
||||||
|
):
|
||||||
|
pass
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -309,6 +309,10 @@ if True:
|
||||||
if True:
|
if True:
|
||||||
with anyio.CancelScope(shield=True) if get_running_loop() else contextlib.nullcontext():
|
with anyio.CancelScope(shield=True) if get_running_loop() else contextlib.nullcontext():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
with Child(aaaaaaaaa, bbbbbbbbbbbbbbb, cccccc), Document(aaaaa, bbbbbbbbbb, ddddddddddddd):
|
||||||
|
pass
|
||||||
```
|
```
|
||||||
|
|
||||||
## Output
|
## Output
|
||||||
|
@ -640,6 +644,12 @@ if True:
|
||||||
shield=True
|
shield=True
|
||||||
) if get_running_loop() else contextlib.nullcontext():
|
) if get_running_loop() else contextlib.nullcontext():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
with Child(aaaaaaaaa, bbbbbbbbbbbbbbb, cccccc), Document(
|
||||||
|
aaaaa, bbbbbbbbbb, ddddddddddddd
|
||||||
|
):
|
||||||
|
pass
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue