[ty] Fix hover showing Unknown for bare Final instance attributes#23003
[ty] Fix hover showing Unknown for bare Final instance attributes#23003
Unknown for bare Final instance attributes#23003Conversation
Typing conformance resultsNo changes detected ✅ |
|
|
I assume the behavior here is intentionally different from how name assignments are handled? This PR makes them more consistent, but I'm likely overlooking the reason that they diverge today. |
sharkdp
left a comment
There was a problem hiding this comment.
Thank you, this seems very reasonable to me.
I assume the behavior here is intentionally different from how name assignments are handled? This PR makes them more consistent, but I'm likely overlooking the reason that they diverge today.
I do not recall any intentional divergence of behavior. A reveal_type(self.a) immediately following the self.a: <type> = <rhs-expr> annotated attribute assignment would also show the RHS type (due to attribute assignment narrowing). So I think this makes sense.
Note that this will not just affect bare Final annotations, but also something like self.a: int = 1 where we previously revealed int instead of Literal[1].
Summary
For non-name annotated assignment targets like
self.x: Final = value, the expression type stored forself.xwas the annotation's inner type (Unknown, forFinal).The name-target path (
x: Final = value) already stores the inferred RHS type instead, so we now do the same for attributes.Closes astral-sh/ty#2509.