From 20d7ae0676be4931d0b2e6d4a6a0877070264d13 Mon Sep 17 00:00:00 2001 From: Batuhan Taskaya Date: Thu, 2 Dec 2021 20:58:22 +0300 Subject: [PATCH 1/1] Ensure match/case are recognized as statements (#2665) --- CHANGES.md | 1 + src/black/nodes.py | 2 ++ tests/data/pattern_matching_style.py | 27 +++++++++++++++++++++++++++ tests/test_format.py | 1 + 4 files changed, 31 insertions(+) create mode 100644 tests/data/pattern_matching_style.py diff --git a/CHANGES.md b/CHANGES.md index 5904291..c9a4f09 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 36dd189..437051d 100644 --- a/src/black/nodes.py +++ b/src/black/nodes.py @@ -52,6 +52,8 @@ STATEMENT: Final = { 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 0000000..c1c0aee --- /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 f97d716..d44be1e 100644 --- a/tests/test_format.py +++ b/tests/test_format.py @@ -74,6 +74,7 @@ PY310_CASES = [ "pattern_matching_simple", "pattern_matching_complex", "pattern_matching_extras", + "pattern_matching_style", "parenthesized_context_managers", ] -- 2.39.5