From e64949ee69e2a7e7f1d96331f50e801c0979a866 Mon Sep 17 00:00:00 2001 From: Batuhan Taskaya Date: Fri, 7 Jan 2022 19:51:36 +0300 Subject: [PATCH] Fix call patterns that contain as-expression on the kwargs (#2749) --- CHANGES.md | 2 ++ src/blib2to3/Grammar.txt | 2 +- tests/data/pattern_matching_extras.py | 14 ++++++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index bfecbb7..ec2f5dc 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -12,6 +12,8 @@ (#2686) - Fix cases that contain multiple top-level as-expressions, like `case 1 as a, 2 as b` (#2716) +- Fix call patterns that contain as-expressions with keyword arguments, like + `case Foo(bar=baz as quux)` (#2749) - 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) diff --git a/src/blib2to3/Grammar.txt b/src/blib2to3/Grammar.txt index 27776a3..cf4799f 100644 --- a/src/blib2to3/Grammar.txt +++ b/src/blib2to3/Grammar.txt @@ -187,7 +187,7 @@ arglist: argument (',' argument)* [','] argument: ( test [comp_for] | test ':=' test | test 'as' test | - test '=' test | + test '=' asexpr_test | '**' test | '*' test ) diff --git a/tests/data/pattern_matching_extras.py b/tests/data/pattern_matching_extras.py index b652d26..9f6907f 100644 --- a/tests/data/pattern_matching_extras.py +++ b/tests/data/pattern_matching_extras.py @@ -103,3 +103,17 @@ match something: case 4 as d, (5 as e), (6 | 7 as g), *h: pass + + +match bar1: + case Foo(aa=Callable() as aa, bb=int()): + print(bar1.aa, bar1.bb) + case _: + print("no match", "\n") + + +match bar1: + case Foo( + normal=x, perhaps=[list, {an: d, dict: 1.0}] as y, otherwise=something, q=t as u + ): + pass -- 2.39.5