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:
Charlie Marsh 2023-09-27 19:57:18 -04:00 committed by GitHub
parent c8360a1333
commit 58b50a6290
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 88 additions and 8 deletions

View file

@ -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
```