Skip to content

Commit 61b48f1

Browse files
authored
Merge pull request #4488 from charliermarsh/charlie/gen-exp-arg
Use entire range for generators-as-arguments
2 parents cf54a78 + d4207e2 commit 61b48f1

File tree

4 files changed

+350
-3
lines changed

4 files changed

+350
-3
lines changed

.cspell.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"bindgen",
3131
"cstring",
3232
"chrono",
33+
"insta",
3334
"peekable",
3435
"lalrpop",
3536
"memmap",

compiler/parser/python.lalrpop

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1274,11 +1274,11 @@ ArgumentList: ArgumentList = {
12741274
};
12751275

12761276
FunctionArgument: (Option<(ast::Location, ast::Location, Option<String>)>, ast::Expr) = {
1277-
<e:NamedExpressionTest> <c:CompFor?> => {
1277+
<location:@L> <e:NamedExpressionTest> <c:CompFor?> <end_location:@R> => {
12781278
let expr = match c {
12791279
Some(c) => ast::Expr {
1280-
location: e.location,
1281-
end_location: e.end_location,
1280+
location,
1281+
end_location: Some(end_location),
12821282
custom: (),
12831283
node: ast::ExprKind::GeneratorExp {
12841284
elt: Box::new(e),

compiler/parser/src/parser.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,19 @@ with (0 as a, 1 as b,): pass
310310
}
311311
}
312312

313+
#[test]
314+
fn test_generator_expression_argument() {
315+
let source = r#"' '.join(
316+
sql
317+
for sql in (
318+
"LIMIT %d" % limit if limit else None,
319+
("OFFSET %d" % offset) if offset else None,
320+
)
321+
)"#;
322+
let parse_ast = parse_expression(source, "<test>").unwrap();
323+
insta::assert_debug_snapshot!(parse_ast);
324+
}
325+
313326
#[test]
314327
fn test_dict_unpacking() {
315328
let parse_ast = parse_expression(r#"{"a": "b", **c, "d": "e"}"#, "<test>").unwrap();

compiler/parser/src/snapshots/rustpython_parser__parser__tests__generator_expression_argument.snap

Lines changed: 333 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)