mirror of
https://github.com/astral-sh/ruff.git
synced 2025-11-01 04:18:05 +00:00
Avoid expanding single-element tuple patterns (#7683)
## Summary The formatting for tuple patterns is now intended to match that of `for` loops: - Always parenthesize single-element tuples. - Don't break on the trailing comma in single-element tuples. - For other tuples, preserve the parentheses, and insert if-breaks. Closes https://github.com/astral-sh/ruff/issues/7681. ## Test Plan `cargo test`
This commit is contained in:
parent
c8360a1333
commit
58b50a6290
3 changed files with 88 additions and 8 deletions
|
|
@ -507,6 +507,27 @@ match pattern_match_or:
|
|||
# own line
|
||||
):
|
||||
...
|
||||
|
||||
|
||||
# Single-element tuples.
|
||||
match pattern:
|
||||
case (a,):
|
||||
pass
|
||||
|
||||
case (a, b):
|
||||
pass
|
||||
|
||||
case (a, b,):
|
||||
pass
|
||||
|
||||
case a,:
|
||||
pass
|
||||
|
||||
case a, b:
|
||||
pass
|
||||
|
||||
case a, b,:
|
||||
pass
|
||||
```
|
||||
|
||||
## Output
|
||||
|
|
@ -1038,6 +1059,33 @@ match pattern_match_or:
|
|||
# own line
|
||||
):
|
||||
...
|
||||
|
||||
|
||||
# Single-element tuples.
|
||||
match pattern:
|
||||
case (a,):
|
||||
pass
|
||||
|
||||
case (a, b):
|
||||
pass
|
||||
|
||||
case (
|
||||
a,
|
||||
b,
|
||||
):
|
||||
pass
|
||||
|
||||
case (a,):
|
||||
pass
|
||||
|
||||
case a, b:
|
||||
pass
|
||||
|
||||
case (
|
||||
a,
|
||||
b,
|
||||
):
|
||||
pass
|
||||
```
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue