Skip to content

Commit 1f28b96

Browse files
committed
bypass multi-inference for named expressions
1 parent 3b2264c commit 1f28b96

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

crates/ty_python_semantic/src/types/context.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,11 @@ impl<'db, 'ctx> DiagnosticGuardBuilder<'db, 'ctx> {
594594
if !ctx.db.should_check_file(ctx.file) {
595595
return None;
596596
}
597+
// If this lint is being reported as part of multi-inference of a given expression,
598+
// silence it to avoid duplicated diagnostics.
599+
if ctx.is_in_multi_inference() {
600+
return None;
601+
}
597602
Some(DiagnosticGuardBuilder { ctx, id, severity })
598603
}
599604

crates/ty_python_semantic/src/types/infer/builder.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5203,14 +5203,23 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> {
52035203
ast::Expr::Compare(compare) => self.infer_compare_expression(compare),
52045204
ast::Expr::Subscript(subscript) => self.infer_subscript_expression(subscript),
52055205
ast::Expr::Slice(slice) => self.infer_slice_expression(slice),
5206-
ast::Expr::Named(named) => self.infer_named_expression(named),
52075206
ast::Expr::If(if_expression) => self.infer_if_expression(if_expression),
52085207
ast::Expr::Lambda(lambda_expression) => self.infer_lambda_expression(lambda_expression),
52095208
ast::Expr::Call(call_expression) => self.infer_call_expression(call_expression, tcx),
52105209
ast::Expr::Starred(starred) => self.infer_starred_expression(starred),
52115210
ast::Expr::Yield(yield_expression) => self.infer_yield_expression(yield_expression),
52125211
ast::Expr::YieldFrom(yield_from) => self.infer_yield_from_expression(yield_from),
52135212
ast::Expr::Await(await_expression) => self.infer_await_expression(await_expression),
5213+
ast::Expr::Named(named) => {
5214+
// Definitions must be unique, so we bypass multi-inference for named expressions.
5215+
if !self.multi_inference_state.is_panic()
5216+
&& let Some(ty) = self.expressions.get(&expression.into())
5217+
{
5218+
return *ty;
5219+
}
5220+
5221+
self.infer_named_expression(named)
5222+
}
52145223
ast::Expr::IpyEscapeCommand(_) => {
52155224
todo_type!("Ipy escape command support")
52165225
}

0 commit comments

Comments
 (0)