From: Batuhan Taskaya Date: Tue, 30 Nov 2021 15:52:25 +0000 (+0300) Subject: Allow top-level starred expression on match (#2659) X-Git-Url: https://git.madduck.net/etc/vim.git/commitdiff_plain/8cdac18a04b64376e87c716cb9c2eafd182e63ff?hp=a066a2bc8b1b7d87b2029f5ebd684582231b0bbc Allow top-level starred expression on match (#2659) Fixes #2647 --- diff --git a/CHANGES.md b/CHANGES.md index 57af2c5..4a8ee0e 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -8,7 +8,8 @@ cell magics were tokenized, leading to possible indentation errors e.g. with `%%writefile`. (#2630) - Fixed Python 3.10 support on platforms without ProcessPoolExecutor (#2631) -- Fixed `match` statements with open sequence subjects, like `match a, b:` (#2639) +- Fixed `match` statements with open sequence subjects, like `match a, b:` or + `match a, *b:` (#2639) (#2659) - Fixed assignment to environment variables in Jupyter Notebooks (#2642) - Add `flake8-simplify` and `flake8-comprehensions` plugins (#2653) diff --git a/src/blib2to3/Grammar.txt b/src/blib2to3/Grammar.txt index de9a6a2..c3001e8 100644 --- a/src/blib2to3/Grammar.txt +++ b/src/blib2to3/Grammar.txt @@ -238,7 +238,11 @@ yield_arg: 'from' test | testlist_star_expr # to reformat them. match_stmt: "match" subject_expr ':' NEWLINE INDENT case_block+ DEDENT -subject_expr: namedexpr_test (',' namedexpr_test)* [','] + +# This is more permissive than the actual version. For example it +# accepts `match *something:`, even though single-item starred expressions +# are forbidden. +subject_expr: (namedexpr_test|star_expr) (',' (namedexpr_test|star_expr))* [','] # cases case_block: "case" patterns [guard] ':' suite diff --git a/tests/data/pattern_matching_extras.py b/tests/data/pattern_matching_extras.py index d4bba38..7061485 100644 --- a/tests/data/pattern_matching_extras.py +++ b/tests/data/pattern_matching_extras.py @@ -43,3 +43,10 @@ match more := (than, one), indeed,: pass case _: pass + + +match a, *b, c: + case [*_]: + return "seq" + case {}: + return "map"