Show the type alias's name on hover
Hovering a type alias currently reveals the aliased type.
We should show the type alias's definition instead, similar to pylance and resolve the documentation etc from the target
I'm going to try my hand at this over the weekend :)
Actually postponing working on this, before actually implementing anything I want to confirm the exact hover behavior, esp for PEP 695 type aliases.
Right now, with Pylance on Python 3.12, I see:
T = int # hover T: `(type) T = int` + docs for int
type U = int # hover U: `(type) U = TypeAliasType` + docs for int
class Test:
t: T # hover t: `(variable) t: int`
# hover T: `(type) T = int` + docs for int
u: U # hover u: `(variable) u: int`
# hover U: `(type) U = type[int]` + docs for int
The only consistent part is that the docs always comes from the aliased target.
Also Pylance leaks internal representation (TypeAliasType / type[int]).
However, T = int and type U = int are not the same thing at runtime (the former binds T directly to int, while the latter is a TypeAliasType object), so I think it’s important to hint at that, but without weighing things down by mentioning TypeAliasType in the hover.
What I'm thinking for ty:
T = int # hover T: `(type) T = int` + docs for int
type U = int # hover U: `(type alias) type U = int` + docs for int
class Test:
t: T # hover t: `(variable) t: T (int)`
# hover T: `(type) T = int` + docs for int
u: U # hover u: `(variable) u: U (int)`
# hover U: `(type alias) type U = int` + docs for int
type Box[T] = list[T]
x: Box[int] # hover x: `(variable) x: Box[int] (list[int])`
# hover Box: `(type alias) type Box[T] = list[T]` + docs for list
-
T = intpresented as a plain type binding:(type) T = int. -
type U = int/type Box[T] = ...presented as first-class alias objects:(type alias) type U = int, etc. - Variables always show
user written-annotation (resolved-type).
Does this behavior match what you’d like for ty?