From 110109aee6746f627ed45794d7bf91ee7abbbfae Mon Sep 17 00:00:00 2001 From: Zsolt Dollenstein Date: Sat, 27 May 2023 10:07:19 +0100 Subject: [PATCH] Allow walrus in slices See https://github.com/python/cpython/pull/23317 Raised in #930. --- native/libcst/src/parser/grammar.rs | 2 +- native/libcst/tests/fixtures/wonky_walrus.py | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/native/libcst/src/parser/grammar.rs b/native/libcst/src/parser/grammar.rs index 14622c1a9..5e23357d3 100644 --- a/native/libcst/src/parser/grammar.rs +++ b/native/libcst/src/parser/grammar.rs @@ -1004,7 +1004,7 @@ parser! { make_slice(l, col, u, rest) } / e:starred_expression() { make_index_from_arg(e) } - / v:expression() { make_index(v) } + / v:named_expression() { make_index(v) } rule atom() -> Expression<'input, 'a> = n:name() { Expression::Name(Box::new(n)) } diff --git a/native/libcst/tests/fixtures/wonky_walrus.py b/native/libcst/tests/fixtures/wonky_walrus.py index d0916ab80..d506b169b 100644 --- a/native/libcst/tests/fixtures/wonky_walrus.py +++ b/native/libcst/tests/fixtures/wonky_walrus.py @@ -10,4 +10,6 @@ if f := x(): pass f(y:=1) -f(x, y := 1 ) \ No newline at end of file +f(x, y := 1 ) + +_[_:=10] \ No newline at end of file