From fb11171a9b0969dc9128c5ecb7455f70614bfad6 Mon Sep 17 00:00:00 2001 From: Carl Meyer Date: Thu, 9 Oct 2025 15:57:54 -0700 Subject: [PATCH] [ty] avoid standalone expressions for simple subscript targets --- crates/ty_python_semantic/src/semantic_index/builder.rs | 7 ++++--- crates/ty_python_semantic/src/types/infer/builder.rs | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/crates/ty_python_semantic/src/semantic_index/builder.rs b/crates/ty_python_semantic/src/semantic_index/builder.rs index b7d19d075b..df10426441 100644 --- a/crates/ty_python_semantic/src/semantic_index/builder.rs +++ b/crates/ty_python_semantic/src/semantic_index/builder.rs @@ -1626,10 +1626,11 @@ impl<'ast> Visitor<'ast> for SemanticIndexBuilder<'_, 'ast> { self.visit_expr(&node.value); // Optimization for the common case: if there's just one target, and it's not an - // unpacking, and the target is a simple name, we don't need the RHS to be a - // standalone expression at all. + // unpacking, and the target is a simple name or subscript, we don't need the RHS + // to be a standalone expression at all. (We do still need standalone expressions + // for attribute targets, for implicit-attribute handling.) if let [target] = &node.targets[..] - && target.is_name_expr() + && (target.is_name_expr() || target.is_subscript_expr()) { self.push_assignment(CurrentAssignment::Assign { node, unpack: None }); self.visit_expr(target); diff --git a/crates/ty_python_semantic/src/types/infer/builder.rs b/crates/ty_python_semantic/src/types/infer/builder.rs index 2ab009025e..490f0ec34f 100644 --- a/crates/ty_python_semantic/src/types/infer/builder.rs +++ b/crates/ty_python_semantic/src/types/infer/builder.rs @@ -3215,7 +3215,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { for target in targets { self.infer_target(target, value, |builder, value_expr| { - builder.infer_standalone_expression(value_expr, TypeContext::default()) + builder.infer_maybe_standalone_expression(value_expr, TypeContext::default()) }); } }