From dfa45cec9e4991823b06fa655e3e444391fadb65 Mon Sep 17 00:00:00 2001 From: Batuhan Taskaya Date: Thu, 25 Nov 2021 04:21:36 +0300 Subject: [PATCH] grammar: accept open sequences on match subject (GH-2639) * grammar: accept open sequences on match subject * give an example about the fixed 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 db519ac..94d1c69 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, like `match a, b:` (#2639) ## 21.11b1 diff --git a/src/blib2to3/Grammar.txt b/src/blib2to3/Grammar.txt index c2a6254..de9a6a2 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 614e66a..d4bba38 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 -- 2.39.5