From fd5c48c53953ff70501c649dedce306dad8ba553 Mon Sep 17 00:00:00 2001 From: Matthew Mckee Date: Tue, 23 Sep 2025 12:14:46 +0100 Subject: [PATCH] [ty] Add support for inlay hints on attribute assignment (#20485) --- crates/ty_ide/src/inlay_hints.rs | 34 ++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/crates/ty_ide/src/inlay_hints.rs b/crates/ty_ide/src/inlay_hints.rs index 2ab77f2f1f..64ce9b9c15 100644 --- a/crates/ty_ide/src/inlay_hints.rs +++ b/crates/ty_ide/src/inlay_hints.rs @@ -264,6 +264,15 @@ impl SourceOrderVisitor<'_> for InlayHintVisitor<'_, '_> { } source_order::walk_expr(self, expr); } + Expr::Attribute(attribute) => { + if self.in_assignment { + if attribute.ctx.is_store() { + let ty = expr.inferred_type(&self.model); + self.add_type_hint(expr.range().end(), ty); + } + } + source_order::walk_expr(self, expr); + } Expr::Call(call) => { let argument_names = inlay_hint_function_argument_details(self.db, &self.model, call) @@ -436,6 +445,31 @@ mod tests { "); } + #[test] + fn test_assign_attribute_of_instance() { + let test = inlay_hint_test( + " + class A: + def __init__(self, y): + self.x = 1 + self.y = y + + a = A(2) + a.y = 3 + ", + ); + + assert_snapshot!(test.inlay_hints(), @r" + class A: + def __init__(self, y): + self.x[: Literal[1]] = 1 + self.y[: Unknown] = y + + a[: A] = A([y=]2) + a.y[: Literal[3]] = 3 + "); + } + #[test] fn test_disabled_variable_types() { let test = inlay_hint_test("x = 1");