Skip to content

Commit

Permalink
Ensure match/case are recognized as statements (#2665)
Browse files Browse the repository at this point in the history
  • Loading branch information
isidentical committed Dec 2, 2021
1 parent b0c2bcc commit 20d7ae0
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
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

0 comments on commit 20d7ae0

Please sign in to comment.