Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support multiple top-level as-expressions on case statements #2716

Merged
merged 1 commit into from
Dec 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
underlying SyntaxError (#2693)
- Fix mapping cases that contain as-expressions, like `case {"key": 1 | 2 as password}`
(#2686)
- Fix cases that contain multiple top-level as-expressions, like `case 1 as a, 2 as b`
(#2716)
- No longer color diff headers white as it's unreadable in light themed terminals
(#2691)
- Tuple unpacking on `return` and `yield` constructs now implies 3.8+ (#2700)
Expand Down
4 changes: 2 additions & 2 deletions src/blib2to3/Grammar.txt
Original file line number Diff line number Diff line change
Expand Up @@ -247,5 +247,5 @@ subject_expr: (namedexpr_test|star_expr) (',' (namedexpr_test|star_expr))* [',']
# cases
case_block: "case" patterns [guard] ':' suite
guard: 'if' namedexpr_test
patterns: pattern ['as' pattern]
pattern: (expr|star_expr) (',' (expr|star_expr))* [',']
patterns: pattern (',' pattern)* [',']
isidentical marked this conversation as resolved.
Show resolved Hide resolved
pattern: (expr|star_expr) ['as' expr]
11 changes: 11 additions & 0 deletions tests/data/pattern_matching_extras.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,14 @@ def func(match: case, case: match) -> case:
pass
case {"maybe": something(complicated as this) as that}:
pass


match something:
case 1 as a:
pass

case 2 as b, 3 as c:
pass

case 4 as d, (5 as e), (6 | 7 as g), *h:
pass