mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-24 19:12:33 +00:00
Misc. follow-ups to single-element tuple patterns (#7698)
Just changes to internal comments and tests. See comments in https://github.com/astral-sh/ruff/pull/7683.
This commit is contained in:
parent
1c02fcd7ce
commit
46b85ab0a9
3 changed files with 140 additions and 1 deletions
|
@ -522,3 +522,45 @@ match pattern:
|
||||||
|
|
||||||
case a, b,:
|
case a, b,:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
case (a, # comment
|
||||||
|
):
|
||||||
|
pass
|
||||||
|
|
||||||
|
case (a, b # comment
|
||||||
|
):
|
||||||
|
pass
|
||||||
|
|
||||||
|
case (a, b, # comment
|
||||||
|
):
|
||||||
|
pass
|
||||||
|
|
||||||
|
case ( # comment
|
||||||
|
a,
|
||||||
|
):
|
||||||
|
pass
|
||||||
|
|
||||||
|
case ( # comment
|
||||||
|
a, b
|
||||||
|
):
|
||||||
|
pass
|
||||||
|
|
||||||
|
case ( # comment
|
||||||
|
a, b,
|
||||||
|
):
|
||||||
|
pass
|
||||||
|
|
||||||
|
case (
|
||||||
|
# comment
|
||||||
|
a,):
|
||||||
|
pass
|
||||||
|
|
||||||
|
case (
|
||||||
|
# comment
|
||||||
|
a, b):
|
||||||
|
pass
|
||||||
|
|
||||||
|
case (
|
||||||
|
# comment
|
||||||
|
a, b,):
|
||||||
|
pass
|
||||||
|
|
|
@ -22,7 +22,8 @@ impl FormatNodeRule<PatternMatchSequence> for FormatPatternMatchSequence {
|
||||||
let sequence_type = SequenceType::from_pattern(item, f.context().source());
|
let sequence_type = SequenceType::from_pattern(item, f.context().source());
|
||||||
|
|
||||||
match (patterns.as_slice(), sequence_type) {
|
match (patterns.as_slice(), sequence_type) {
|
||||||
// If the sequence is empty, the parentheses with any dangling comments.
|
// If the sequence is empty, format the empty parentheses, along with any dangling
|
||||||
|
// comments.
|
||||||
([], SequenceType::Tuple | SequenceType::TupleNoParens) => {
|
([], SequenceType::Tuple | SequenceType::TupleNoParens) => {
|
||||||
return empty_parenthesized("(", dangling, ")").fmt(f)
|
return empty_parenthesized("(", dangling, ")").fmt(f)
|
||||||
}
|
}
|
||||||
|
|
|
@ -528,6 +528,48 @@ match pattern:
|
||||||
|
|
||||||
case a, b,:
|
case a, b,:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
case (a, # comment
|
||||||
|
):
|
||||||
|
pass
|
||||||
|
|
||||||
|
case (a, b # comment
|
||||||
|
):
|
||||||
|
pass
|
||||||
|
|
||||||
|
case (a, b, # comment
|
||||||
|
):
|
||||||
|
pass
|
||||||
|
|
||||||
|
case ( # comment
|
||||||
|
a,
|
||||||
|
):
|
||||||
|
pass
|
||||||
|
|
||||||
|
case ( # comment
|
||||||
|
a, b
|
||||||
|
):
|
||||||
|
pass
|
||||||
|
|
||||||
|
case ( # comment
|
||||||
|
a, b,
|
||||||
|
):
|
||||||
|
pass
|
||||||
|
|
||||||
|
case (
|
||||||
|
# comment
|
||||||
|
a,):
|
||||||
|
pass
|
||||||
|
|
||||||
|
case (
|
||||||
|
# comment
|
||||||
|
a, b):
|
||||||
|
pass
|
||||||
|
|
||||||
|
case (
|
||||||
|
# comment
|
||||||
|
a, b,):
|
||||||
|
pass
|
||||||
```
|
```
|
||||||
|
|
||||||
## Output
|
## Output
|
||||||
|
@ -1086,6 +1128,60 @@ match pattern:
|
||||||
b,
|
b,
|
||||||
):
|
):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
case (
|
||||||
|
a, # comment
|
||||||
|
):
|
||||||
|
pass
|
||||||
|
|
||||||
|
case (
|
||||||
|
a,
|
||||||
|
b, # comment
|
||||||
|
):
|
||||||
|
pass
|
||||||
|
|
||||||
|
case (
|
||||||
|
a,
|
||||||
|
b, # comment
|
||||||
|
):
|
||||||
|
pass
|
||||||
|
|
||||||
|
case ( # comment
|
||||||
|
a,
|
||||||
|
):
|
||||||
|
pass
|
||||||
|
|
||||||
|
case ( # comment
|
||||||
|
a,
|
||||||
|
b,
|
||||||
|
):
|
||||||
|
pass
|
||||||
|
|
||||||
|
case ( # comment
|
||||||
|
a,
|
||||||
|
b,
|
||||||
|
):
|
||||||
|
pass
|
||||||
|
|
||||||
|
case (
|
||||||
|
# comment
|
||||||
|
a,
|
||||||
|
):
|
||||||
|
pass
|
||||||
|
|
||||||
|
case (
|
||||||
|
# comment
|
||||||
|
a,
|
||||||
|
b,
|
||||||
|
):
|
||||||
|
pass
|
||||||
|
|
||||||
|
case (
|
||||||
|
# comment
|
||||||
|
a,
|
||||||
|
b,
|
||||||
|
):
|
||||||
|
pass
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue