From: Batuhan Taskaya Date: Sun, 12 Dec 2021 21:10:22 +0000 (+0300) Subject: Support as-expressions on dict items (GH-2686) X-Git-Url: https://git.madduck.net/etc/vim.git/commitdiff_plain/1c6b3a3a6fbc50b651d4ac34247903041d3f6329?ds=inline Support as-expressions on dict items (GH-2686) --- diff --git a/CHANGES.md b/CHANGES.md index 3724820..0dcf35e 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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 diff --git a/src/blib2to3/Grammar.txt b/src/blib2to3/Grammar.txt index c3001e8..600712c 100644 --- a/src/blib2to3/Grammar.txt +++ b/src/blib2to3/Grammar.txt @@ -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))* [','])) ) diff --git a/tests/data/pattern_matching_extras.py b/tests/data/pattern_matching_extras.py index 60ad8a3..c00585e 100644 --- a/tests/data/pattern_matching_extras.py +++ b/tests/data/pattern_matching_extras.py @@ -82,3 +82,13 @@ match match: 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