Skip to content

Commit 068e73e

Browse files
committed
visit generators in surrounding scope
1 parent 58b156f commit 068e73e

File tree

3 files changed

+144
-184
lines changed

3 files changed

+144
-184
lines changed

crates/ruff_python_parser/resources/valid/expressions/list_comprehension.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
[1 for i in x in a]
88
[a for a, b in G]
99
def outer():
10-
[
11-
await x for a, b in C
12-
]
1310
[i for i in await x if entity is not None]
1411
[x for x in (l if True else L) if T]
1512
def outer():

crates/ruff_python_parser/tests/fixtures.rs

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -602,13 +602,35 @@ impl Visitor<'_> for SemanticSyntaxCheckerVisitor<'_> {
602602
ast::visitor::walk_expr(self, expr);
603603
self.scopes.pop().unwrap();
604604
}
605-
ast::Expr::ListComp(ast::ExprListComp { generators, .. })
606-
| ast::Expr::SetComp(ast::ExprSetComp { generators, .. })
607-
| ast::Expr::DictComp(ast::ExprDictComp { generators, .. }) => {
605+
ast::Expr::ListComp(ast::ExprListComp {
606+
elt, generators, ..
607+
})
608+
| ast::Expr::SetComp(ast::ExprSetComp {
609+
elt, generators, ..
610+
}) => {
611+
for comprehension in generators {
612+
self.visit_comprehension(comprehension);
613+
}
608614
self.scopes.push(Scope::Comprehension {
609615
is_async: generators.iter().any(|gen| gen.is_async),
610616
});
611-
ast::visitor::walk_expr(self, expr);
617+
self.visit_expr(elt);
618+
self.scopes.pop().unwrap();
619+
}
620+
ast::Expr::DictComp(ast::ExprDictComp {
621+
key,
622+
value,
623+
generators,
624+
..
625+
}) => {
626+
for comprehension in generators {
627+
self.visit_comprehension(comprehension);
628+
}
629+
self.scopes.push(Scope::Comprehension {
630+
is_async: generators.iter().any(|gen| gen.is_async),
631+
});
632+
self.visit_expr(key);
633+
self.visit_expr(value);
612634
self.scopes.pop().unwrap();
613635
}
614636
_ => {

0 commit comments

Comments
 (0)