From 5ce49549432d69d463cfa86a5a6f4a10a02a7019 Mon Sep 17 00:00:00 2001 From: Batuhan Taskaya Date: Wed, 24 Nov 2021 20:10:05 +0300 Subject: [PATCH 1/2] grammar: accept open sequences on match subject --- CHANGES.md | 1 + src/blib2to3/Grammar.txt | 2 +- tests/data/pattern_matching_extras.py | 16 ++++++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index db519ac6bbc..d99a82953f1 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -5,6 +5,7 @@ ### _Black_ - Fixed Python 3.10 support on platforms without ProcessPoolExecutor (#2631) +- Fixed `match` statements with open sequence subjects (#2639) ## 21.11b1 diff --git a/src/blib2to3/Grammar.txt b/src/blib2to3/Grammar.txt index c2a62543abb..de9a6a2283f 100644 --- a/src/blib2to3/Grammar.txt +++ b/src/blib2to3/Grammar.txt @@ -238,7 +238,7 @@ yield_arg: 'from' test | testlist_star_expr # to reformat them. match_stmt: "match" subject_expr ':' NEWLINE INDENT case_block+ DEDENT -subject_expr: namedexpr_test +subject_expr: namedexpr_test (',' namedexpr_test)* [','] # cases case_block: "case" patterns [guard] ':' suite diff --git a/tests/data/pattern_matching_extras.py b/tests/data/pattern_matching_extras.py index 614e66aebe6..d4bba38ee7c 100644 --- a/tests/data/pattern_matching_extras.py +++ b/tests/data/pattern_matching_extras.py @@ -27,3 +27,19 @@ def func(match: case, case: match) -> case: ... case func(match, case): ... + + +match maybe, multiple: + case perhaps, 5: + pass + case perhaps, 6,: + pass + + +match more := (than, one), indeed,: + case _, (5, 6): + pass + case [[5], (6)], [7],: + pass + case _: + pass From ef8f4c30045afb42f95fa634ae762bade4d6eda4 Mon Sep 17 00:00:00 2001 From: Batuhan Taskaya Date: Wed, 24 Nov 2021 20:46:26 +0300 Subject: [PATCH 2/2] give an example about the fixed match subject --- CHANGES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index d99a82953f1..94d1c69259a 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -5,7 +5,7 @@ ### _Black_ - Fixed Python 3.10 support on platforms without ProcessPoolExecutor (#2631) -- Fixed `match` statements with open sequence subjects (#2639) +- Fixed `match` statements with open sequence subjects, like `match a, b:` (#2639) ## 21.11b1