Support as-expressions on dict items (GH-2686)

This commit is contained in:
Batuhan Taskaya 2021-12-13 00:10:22 +03:00 committed by GitHub
parent e7ddf524b0
commit 1c6b3a3a6f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 2 deletions

View File

@ -5,6 +5,8 @@
### _Black_ ### _Black_
- Improve error message for invalid regular expression (#2678) - 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 ## 21.12b0

View File

@ -168,8 +168,8 @@ subscript: test [':=' test] | [test] ':' [test] [sliceop]
sliceop: ':' [test] sliceop: ':' [test]
exprlist: (expr|star_expr) (',' (expr|star_expr))* [','] exprlist: (expr|star_expr) (',' (expr|star_expr))* [',']
testlist: test (',' test)* [','] testlist: test (',' test)* [',']
dictsetmaker: ( ((test ':' test | '**' expr) dictsetmaker: ( ((test ':' asexpr_test | '**' expr)
(comp_for | (',' (test ':' test | '**' expr))* [','])) | (comp_for | (',' (test ':' asexpr_test | '**' expr))* [','])) |
((test [':=' test] | star_expr) ((test [':=' test] | star_expr)
(comp_for | (',' (test [':=' test] | star_expr))* [','])) ) (comp_for | (',' (test [':=' test] | star_expr))* [','])) )

View File

@ -82,3 +82,13 @@ def func(match: case, case: match) -> case:
match a, *b(), c: match a, *b(), c:
case d, *f, g: case d, *f, g:
pass 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