diff --git a/CHANGES.md b/CHANGES.md index 57af2c5deae..32e829e581a 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 and #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 de9a6a2283f..c3001e81065 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 d4bba38ee7c..706148561a2 100644 --- a/tests/data/pattern_matching_extras.py +++ b/tests/data/pattern_matching_extras.py @@ -43,3 +43,10 @@ def func(match: case, case: match) -> case: pass case _: pass + + +match a, *b, c: + case [*_]: + return "seq" + case {}: + return "map"