diff --git a/parser/src/python.lalrpop b/parser/src/python.lalrpop index 8a252c8acc5..c75cdc294cf 100644 --- a/parser/src/python.lalrpop +++ b/parser/src/python.lalrpop @@ -336,7 +336,7 @@ Atom: ast::Expression = { => ast::Expression::String { value: s }, => ast::Expression::Number { value: n }, => ast::Expression::Identifier { name: i }, - "[" "]" => { + "[" <_trailing_comma:","?> "]" => { match e { None => ast::Expression::List { elements: Vec::new() }, Some(elements) => ast::Expression::List { elements }, @@ -362,7 +362,7 @@ Atom: ast::Expression = { }; TestDict: Vec<(ast::Expression, ast::Expression)> = { - => { + <_trailing_comma:","?> => { let mut d = vec![e1]; d.extend(e2.into_iter().map(|x| x.1)); d diff --git a/tests/snippets/commas.py b/tests/snippets/commas.py new file mode 100644 index 00000000000..ccf9d5857c0 --- /dev/null +++ b/tests/snippets/commas.py @@ -0,0 +1,12 @@ +list1 = ["a", "b",] +list2 = [ + "a", + "b", +] +assert list1 == list2 + +dict1 = {"a": "b",} +dict2 = { + "a": "b", +} +#assert dict1 == dict2