-
Notifications
You must be signed in to change notification settings - Fork 771
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Option to show expanded type instead of type alias on hover #847
Comments
This is similar to #562. Will look at adding a toggle depending on upvotes |
See my comment here: #562 (comment) This current behavior is pretty deliberate. |
@jakebailey Yes, I did realize that this behavior is deliberate after going through other related issues (though missed 562). @judej Thanks. Waiting for sufficient upvotes then on 562. |
This issue (that you opened) would be the place to vote; #562 actually turned out to reveal a bug and has since been fixed. |
@jakebailey Ah, thanks for clarifying. |
@jakebailey I just realised that type aliases do expand on hover or in suggestions when they are part of a |
They expand because Unions are normalized and type alias names get lost. TypeScript recently changed this behavior themselves (as they used to do what we do), but we had been pondering adopting their method to preserve type names as much as possible (which is probably the opposite direction you were hoping for). |
@jakebailey Think about it this way: A type alias allows us to define a large and complex type annotation once and use it multiple times throughout our code, helping to keep it concise and clear. Now say I import the function |
In PyCharm too we get the expanded view in tooltips. |
To share my experience with this, I find it to be a little abrasive from a "developer experience" point of view to need to go-to-def on a type alias that I created more-so to save me from typing out a complicated type, not to "hide" the type. Granted, at some point one must realize that you're probably just abusing the type system and should refactor 😅 but occasionally I stop myself from creating an alias simply so that I can still see the type information at a glance (or, at-least easier than doing a go-to-def on the alias itself). I'd really appreciate the ability to just see the whole type when hovering, or perhaps show the alias and the type it expands to side-by-side when I hover on a variable that uses the alias. The current implementation seems to actively want to discourage type aliasing because of the reasons previously stated (and the reasons other folks have mentioned in this thread). All of this to just say - I'd really like for this to be implemented 🙂 |
Type aliases are a way to manage and hide complexity. A good alias name should reflect its usage. Can you share an example of a type alias that you've defined where its meaning is not clear from its name? If you hover over a type alias name (e.g. within a type annotation), pylance will expand it to show you its definition. In other contexts, the type alias name will stand in for the full type that it represents. We put a lot of effort into retaining and displaying the type alias name because we received feedback from many users that they were overwhelmed by the complexity of the full type, especially when large unions were involved. I'll note that the current hover behavior in pylance is consistent with the behavior of other language servers like TypeScript and C#. |
Yep, understood that you can hover over the alias name itself in the annotation, but if you're dealing with a variable that's getting passed around, you'll have to go to the variable's definition and then hover over the alias definition - an extra step. This is definitely a minor inconvenience for sure, and I agree that aliases themselves should have better naming schemes so that their names make their usage obvious. However, sometimes I've been dealing with code where someone has gotten a bit overzealous with how much heavy lifting the alias is actually doing (where the alias is a nested dict type def that can get quite nasty) and it's not really practical in the short term to break it out into "good" aliases, and in those situations being able to see the full complex type you're dealing with is helpful. I can definitely understand how the complexity of a full type can overwhelm and distract users, hence why I also agree with the premise of this feature request which is to make this an option that users like myself could enable. I for one would appreciate if I could see the alias with it's definition in-line when I hover over a variable that uses that alias. |
Agreed strongly. It seems to me there are (at least) two primary motivations for aliasing types:
On top of that, there are some users who spend all day living inside a single code base with which they are intimately familiar, some users who poke around inside code bases they've never seen before, and some "low-volume" users who infrequently revisit code they once knew intimately. With all that in mind, I'd argue that for a given user and/or situation, less might be more, or more might be more. No software can reasonably be expected to be everything to everyone at all times, but given that VS Code is largely a software development tool, I humbly suggest that if it is going to "err on the side" of something, it should err on the side of showing the user more than they wish to see, rather than on the side of abstracting too much away. |
Moving this issue to discussion as an enhancement request for comments and upvotes. |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
Can we have an option to show the expanded types instead of the type alias on hover ?
If one uses type aliases to shorten and reuse type hint definitions and there are nested type alias definitions across files, then it becomes very difficult to track down the actual type values.
The text was updated successfully, but these errors were encountered: