From 417bfbc2fc73b17431b09e7fae6235367140f434 Mon Sep 17 00:00:00 2001 From: Dhruv Manilawala Date: Mon, 23 Dec 2024 15:46:48 +0530 Subject: [PATCH] [red-knot] Infer value expr for empty list / tuple target --- crates/red_knot_python_semantic/src/types/infer.rs | 10 ++++++++-- crates/red_knot_workspace/tests/check.rs | 6 ++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/crates/red_knot_python_semantic/src/types/infer.rs b/crates/red_knot_python_semantic/src/types/infer.rs index 6111eaf72f6cc..aee508c91fdea 100644 --- a/crates/red_knot_python_semantic/src/types/infer.rs +++ b/crates/red_knot_python_semantic/src/types/infer.rs @@ -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), @@ -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. diff --git a/crates/red_knot_workspace/tests/check.rs b/crates/red_knot_workspace/tests/check.rs index d7d0a14b11d39..04a1ba1c07e7d 100644 --- a/crates/red_knot_workspace/tests/check.rs +++ b/crates/red_knot_workspace/tests/check.rs @@ -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;