Skip to content

Commit

Permalink
Allow top-level starred expression on match
Browse files Browse the repository at this point in the history
  • Loading branch information
isidentical committed Nov 30, 2021
1 parent a066a2b commit eb1806c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
3 changes: 2 additions & 1 deletion CHANGES.md
Expand Up @@ -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)

Expand Down
6 changes: 5 additions & 1 deletion src/blib2to3/Grammar.txt
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions tests/data/pattern_matching_extras.py
Expand Up @@ -43,3 +43,10 @@ def func(match: case, case: match) -> case:
pass
case _:
pass


match a, *b, c:
case [*_]:
return "seq"
case {}:
return "map"

0 comments on commit eb1806c

Please sign in to comment.