[ty] Fix goto for float and complex in type annotation positions by MichaReiser · Pull Request #21388 · astral-sh/ruff (original) (raw)

Summary

I looked into fixing astral-sh/ty#1470, specifically that float and complex are highlighted differently (as Variables instead of classes) compared to int, bool.

The reason for the difference in highlighting is that ty (following the typing spec) expands float and complex in type annotation positions to float | int and complex | float | int, a union.

However, this difference wasn't obvious to me as a user because clicking on float or complex jumped right to class float and class complex in builtins.pyi rather than showing all definitions.

This PR fixes that which, IMO, makes the experience more consistent:

I think we might still want to fix issue astral-sh/ty#1470 separately by highlighting float and complex the same as we would any other type alias.

Test

I added a test for goto definition. I also added a test for semantic highlighting just so that it's already in place.