Skip to content

Commit

Permalink
Support as-expressions on dict items (GH-2686)
Browse files Browse the repository at this point in the history
  • Loading branch information
isidentical committed Dec 12, 2021
1 parent e7ddf52 commit 1c6b3a3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Expand Up @@ -5,6 +5,8 @@
### _Black_

- Improve error message for invalid regular expression (#2678)
- Fix mapping cases that contain as-expressions, like `case {"key": 1 | 2 as password}`
(#2686)

## 21.12b0

Expand Down
4 changes: 2 additions & 2 deletions src/blib2to3/Grammar.txt
Expand Up @@ -168,8 +168,8 @@ subscript: test [':=' test] | [test] ':' [test] [sliceop]
sliceop: ':' [test]
exprlist: (expr|star_expr) (',' (expr|star_expr))* [',']
testlist: test (',' test)* [',']
dictsetmaker: ( ((test ':' test | '**' expr)
(comp_for | (',' (test ':' test | '**' expr))* [','])) |
dictsetmaker: ( ((test ':' asexpr_test | '**' expr)
(comp_for | (',' (test ':' asexpr_test | '**' expr))* [','])) |
((test [':=' test] | star_expr)
(comp_for | (',' (test [':=' test] | star_expr))* [','])) )

Expand Down
10 changes: 10 additions & 0 deletions tests/data/pattern_matching_extras.py
Expand Up @@ -82,3 +82,13 @@ def func(match: case, case: match) -> case:
match a, *b(), c:
case d, *f, g:
pass


match something:
case {
"key": key as key_1,
"password": PASS.ONE | PASS.TWO | PASS.THREE as password,
}:
pass
case {"maybe": something(complicated as this) as that}:
pass

0 comments on commit 1c6b3a3

Please sign in to comment.