Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misc. follow-ups to single-element tuple patterns #7698

Merged
merged 1 commit into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -522,3 +522,45 @@ def foo():

case a, b,:
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
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ impl FormatNodeRule<PatternMatchSequence> for FormatPatternMatchSequence {
let sequence_type = SequenceType::from_pattern(item, f.context().source());

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) => {
return empty_parenthesized("(", dangling, ")").fmt(f)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,48 @@ match pattern:

case a, b,:
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
Expand Down Expand Up @@ -1086,6 +1128,60 @@ match pattern:
b,
):
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
```


Expand Down
Loading