mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-30 05:45:24 +00:00
[red-knot] Handle multiple comprehension targets (#13213)
## Summary Part of #13085, this PR updates the comprehension definition to handle multiple targets. ## Test Plan Update existing semantic index test case for comprehension with multiple targets. Running corpus tests shouldn't panic.
This commit is contained in:
parent
3c4ec82aee
commit
e1e9143c47
4 changed files with 103 additions and 53 deletions
|
@ -285,6 +285,7 @@ impl<'db> SemanticIndexBuilder<'db> {
|
|||
|
||||
// The `iter` of the first generator is evaluated in the outer scope, while all subsequent
|
||||
// nodes are evaluated in the inner scope.
|
||||
self.add_standalone_expression(&generator.iter);
|
||||
self.visit_expr(&generator.iter);
|
||||
self.push_scope(scope);
|
||||
|
||||
|
@ -300,6 +301,7 @@ impl<'db> SemanticIndexBuilder<'db> {
|
|||
}
|
||||
|
||||
for generator in generators_iter {
|
||||
self.add_standalone_expression(&generator.iter);
|
||||
self.visit_expr(&generator.iter);
|
||||
|
||||
self.current_assignment = Some(CurrentAssignment::Comprehension {
|
||||
|
@ -678,7 +680,11 @@ where
|
|||
Some(CurrentAssignment::Comprehension { node, first }) => {
|
||||
self.add_definition(
|
||||
symbol,
|
||||
ComprehensionDefinitionNodeRef { node, first },
|
||||
ComprehensionDefinitionNodeRef {
|
||||
iterable: &node.iter,
|
||||
target: name_node,
|
||||
first,
|
||||
},
|
||||
);
|
||||
}
|
||||
Some(CurrentAssignment::WithItem(with_item)) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue