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

Ensure match/case are recognized as statements #2665

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Expand Up @@ -13,6 +13,7 @@
`match a, *b:` (#2639) (#2659)
- Fix `match`/`case` statements that contain `match`/`case` soft keywords multiple
times, like `match re.match()` (#2661)
- Fix `case` statements with an inline body (#2665)
- Fix assignment to environment variables in Jupyter Notebooks (#2642)
- Add `flake8-simplify` and `flake8-comprehensions` plugins (#2653)
- Fix determination of f-string expression spans (#2654)
Expand Down
2 changes: 2 additions & 0 deletions src/black/nodes.py
Expand Up @@ -52,6 +52,8 @@
syms.with_stmt,
syms.funcdef,
syms.classdef,
syms.match_stmt,
syms.case_block,
}
STANDALONE_COMMENT: Final = 153
token.tok_name[STANDALONE_COMMENT] = "STANDALONE_COMMENT"
Expand Down
27 changes: 27 additions & 0 deletions tests/data/pattern_matching_style.py
@@ -0,0 +1,27 @@
match something:
case b(): print(1+1)
case c(
very_complex=True,
perhaps_even_loooooooooooooooooooooooooooooooooooooong=- 1
): print(1)
case c(
very_complex=True,
perhaps_even_loooooooooooooooooooooooooooooooooooooong=-1
): print(2)
case a: pass

# output

match something:
case b():
print(1 + 1)
case c(
very_complex=True, perhaps_even_loooooooooooooooooooooooooooooooooooooong=-1
):
print(1)
case c(
very_complex=True, perhaps_even_loooooooooooooooooooooooooooooooooooooong=-1
):
print(2)
case a:
pass
1 change: 1 addition & 0 deletions tests/test_format.py
Expand Up @@ -74,6 +74,7 @@
"pattern_matching_simple",
"pattern_matching_complex",
"pattern_matching_extras",
"pattern_matching_style",
"parenthesized_context_managers",
]

Expand Down