diff --git a/CHANGES.md b/CHANGES.md index 59042914174..c9a4f09a72a 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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) diff --git a/src/black/nodes.py b/src/black/nodes.py index 36dd1890511..437051d3f6d 100644 --- a/src/black/nodes.py +++ b/src/black/nodes.py @@ -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" diff --git a/tests/data/pattern_matching_style.py b/tests/data/pattern_matching_style.py new file mode 100644 index 00000000000..c1c0aeedb70 --- /dev/null +++ b/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 diff --git a/tests/test_format.py b/tests/test_format.py index f97d7165b1a..d44be1e8712 100644 --- a/tests/test_format.py +++ b/tests/test_format.py @@ -74,6 +74,7 @@ "pattern_matching_simple", "pattern_matching_complex", "pattern_matching_extras", + "pattern_matching_style", "parenthesized_context_managers", ]