From 88279ccacb57fd777a45c2c356a18710dad9532c Mon Sep 17 00:00:00 2001 From: Carl Meyer Date: Fri, 12 Dec 2025 09:19:24 -0800 Subject: [PATCH] [ty] fix hover type on named expression target --- crates/ty_ide/src/hover.rs | 31 +++++++++++++++++++ .../src/types/infer/builder.rs | 6 ++-- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/crates/ty_ide/src/hover.rs b/crates/ty_ide/src/hover.rs index 8430a46edc..7389b4c1cc 100644 --- a/crates/ty_ide/src/hover.rs +++ b/crates/ty_ide/src/hover.rs @@ -3624,6 +3624,37 @@ def function(): assert_snapshot!(test.hover(), @"Hover provided no content"); } + #[test] + fn hover_named_expression_target() { + let test = CursorTest::builder() + .source( + "mymod.py", + r#" + if a := 10: + pass + "#, + ) + .build(); + + assert_snapshot!(test.hover(), @r###" + Literal[10] + --------------------------------------------- + ```python + Literal[10] + ``` + --------------------------------------------- + info[hover]: Hovered content is + --> mymod.py:2:4 + | + 2 | if a := 10: + | ^- Cursor offset + | | + | source + 3 | pass + | + "###); + } + impl CursorTest { fn hover(&self) -> String { use std::fmt::Write; diff --git a/crates/ty_python_semantic/src/types/infer/builder.rs b/crates/ty_python_semantic/src/types/infer/builder.rs index 57e3df8eb9..6df802b691 100644 --- a/crates/ty_python_semantic/src/types/infer/builder.rs +++ b/crates/ty_python_semantic/src/types/infer/builder.rs @@ -8164,10 +8164,10 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { value, } = named; - self.infer_expression(target, TypeContext::default()); - self.add_binding(named.target.as_ref().into(), definition, |builder, tcx| { - builder.infer_expression(value, tcx) + let ty = builder.infer_expression(value, tcx); + builder.store_expression_type(target, ty); + ty }) }