Skip to content

Commit

Permalink
[red-knot] Infer value expr for empty list / tuple target
Browse files Browse the repository at this point in the history
  • Loading branch information
dhruvmanila committed Dec 23, 2024
1 parent 113c804 commit 417bfbc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
10 changes: 8 additions & 2 deletions crates/red_knot_python_semantic/src/types/infer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1826,11 +1826,14 @@ impl<'db> TypeInferenceBuilder<'db> {
}
}

/// Infer the definition type involved in a `target` expression.
/// Infer the definition types involved in a `target` expression.
///
/// This is used for assignment statements, for statements, etc. with a single or multiple
/// targets (unpacking).
// TODO: Remove the `value` argument once we handle all possible assignment targets.
///
/// # Panics
///
/// If the `value` is not a standalone expression.
fn infer_target(&mut self, target: &ast::Expr, value: &ast::Expr) {
match target {
ast::Expr::Name(name) => self.infer_definition(name),
Expand All @@ -1839,6 +1842,9 @@ impl<'db> TypeInferenceBuilder<'db> {
for element in elts {
self.infer_target(element, value);
}
if elts.is_empty() {
self.infer_standalone_expression(value);
}
}
_ => {
// TODO: Remove this once we handle all possible assignment targets.
Expand Down
6 changes: 2 additions & 4 deletions crates/red_knot_workspace/tests/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,14 +207,12 @@ impl SourceOrderVisitor<'_> for PullTypesVisitor<'_> {
for target in &assign.targets {
self.visit_target(target);
}
// TODO
//self.visit_expr(&assign.value);
self.visit_expr(&assign.value);
return;
}
Stmt::For(for_stmt) => {
self.visit_target(&for_stmt.target);
// TODO
//self.visit_expr(&for_stmt.iter);
self.visit_expr(&for_stmt.iter);
self.visit_body(&for_stmt.body);
self.visit_body(&for_stmt.orelse);
return;
Expand Down

0 comments on commit 417bfbc

Please sign in to comment.