Highlight type variables as types #2695
Replies: 8 comments
-
The three symbols in your example above are all examples of "type aliases". Most languages provide a syntax for defining type aliases, but Python uses the same syntax for variables and type aliases. PEP 613, which will be in Python 3.10, starts to address this shortcoming. In the meantime, type analyzers like pylance need to use heuristics to distinguish between a normal variable and a type alias. @bschnurr, do we use a different semantic token for symbols that pyright's heuristics identify as a type alias? I think that's what this feature would require. |
Beta Was this translation helpful? Give feedback.
-
looks like we don't have this logic in yet. There is a "type" token we should be returning instead. |
Beta Was this translation helpful? Give feedback.
-
Any updates? |
Beta Was this translation helpful? Give feedback.
-
This enhancement request has received only a small number of upvotes (thumbs up reactions). We generally use that feedback to prioritize feature work in Pylance. Once a feature request has reached a sufficiently high priority level and the team decides to pursue it, the issue will receive a "Backlog" label. |
Beta Was this translation helpful? Give feedback.
-
Moving this issue to discussion as an enhancement request for comments and upvotes. |
Beta Was this translation helpful? Give feedback.
-
It would be nice to see type aliases highlighted as such. At least in VSCode, it seems to recognize that it is a type alias in the tooltip hint. |
Beta Was this translation helpful? Give feedback.
-
@bschnurr With python 3.12 being a thing and type aliases having their own syntax without the need for importing from Typings, this should really be prioritized, no? |
Beta Was this translation helpful? Give feedback.
-
We have added this item to our backlog. You can track #3100 to track progress. thanks |
Beta Was this translation helpful? Give feedback.
-
Currently, type variables are highlighted as variables. It would make more sense for them to be highlighted as types. This could be done by checking if the variable is an instance of a
typing.TypeVar
or similar types.Some motivating examples:
Currently, these are highlighted as variables. Highlighting them as types would be really helpful for readability.
Beta Was this translation helpful? Give feedback.
All reactions