mirror of https://github.com/astral-sh/ruff
[ty] avoid standalone expressions for simple subscript targets
This commit is contained in:
parent
66885e4bce
commit
fb11171a9b
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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())
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue