Skip to content

Commit 338dede

Browse files
committed
Add test for non-trivial expression on the LHS of a = in argument list.
The documented grammar allows it, but CPython doesn't.
1 parent a703954 commit 338dede

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

Diff for: src/expressions.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ impl<ANS: AreNewlinesSpaces> ExpressionParser<ANS> {
564564
preceded!(tag!("**"), call!(Self::test)) => { |kwargs: Box<_>| Argument::Kwargs(*kwargs) }
565565
| preceded!(char!('*'), call!(Self::test)) => { |args: Box<_>| Argument::Starargs(*args) }
566566
| do_parse!(
567-
name: name >>
567+
name: name >> // According to the grammar, this should be a 'test', but cpython actually refuses it (for good reasons)
568568
value: preceded!(char!('='), call!(Self::test)) >> (
569569
Argument::Keyword(name.to_string(), *value)
570570
)
@@ -1341,6 +1341,20 @@ mod tests {
13411341
);
13421342
}
13431343

1344+
#[test]
1345+
fn test_call_keyword_expr() {
1346+
// The Grammar technically allows this, but CPython refuses it for good reasons;
1347+
// let's do the same.
1348+
let atom_expr = ExpressionParser::<NewlinesAreNotSpaces>::atom_expr;
1349+
assert_parse_eq(
1350+
atom_expr(make_strspan("foo(bar1 if baz else bar2=baz)")),
1351+
Ok((
1352+
make_strspan("(bar1 if baz else bar2=baz)"),
1353+
Box::new(Expression::Name("foo".to_string())),
1354+
)),
1355+
);
1356+
}
1357+
13441358
#[test]
13451359
fn test_subscript_simple() {
13461360
let atom_expr = ExpressionParser::<NewlinesAreNotSpaces>::atom_expr;

0 commit comments

Comments
 (0)