Skip to content

Conversation

mtshiba
Copy link
Contributor

@mtshiba mtshiba commented Oct 15, 2025

Summary

Edit: please merge #20924 first

Closes astral-sh/ty#1348

The variance of a type variable is displayed (next to the type) when hovered over.
They are also displayed in the type parameters list.

This is an enhancement to the language server, but also includes some internal additions to ty_python_semantic (such as calculating variances for type aliases).

Test Plan

New tests in ty_ide/hover/tests.

Copy link
Contributor

github-actions bot commented Oct 15, 2025

Diagnostic diff on typing conformance tests

No changes detected when running ty on typing conformance tests ✅

Copy link
Contributor

github-actions bot commented Oct 15, 2025

mypy_primer results

No ecosystem changes detected ✅
No memory usage changes detected ✅

@mtshiba mtshiba marked this pull request as ready for review October 15, 2025 17:33
@AlexWaygood AlexWaygood added server Related to the LSP server ty Multi-file analysis & type inference labels Oct 15, 2025
Copy link
Member

@AlexWaygood AlexWaygood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@MichaReiser
Copy link
Member

MichaReiser commented Oct 17, 2025

@mtshiba, unfortunately, there are now some merge conflicts.

sharkdp pushed a commit that referenced this pull request Oct 17, 2025
## Summary

Derived from #20900

Implement `VarianceInferable` for `KnownInstanceType` (especially for
`KnownInstanceType::TypeAliasType`).

The variance of a type alias matches its value type. In normal usage,
type aliases are expanded to value types, so the variance of a type
alias can be obtained without implementing this. However, for example,
if we want to display the variance when hovering over a type alias, we
need to be able to obtain the variance of the type alias itself (cf.
#20900).

## Test Plan

I couldn't come up with a way to test this in mdtest, so I'm testing it
in a test submodule at the end of `types.rs`.
I also added a test to `mdtest/generics/pep695/variance.md`, but it
passes without the changes in this PR.
@mtshiba mtshiba marked this pull request as draft October 18, 2025 04:05
@mtshiba
Copy link
Contributor Author

mtshiba commented Oct 19, 2025

Divergence suppression for recursive aliases is addressed in #20969. Please check it out.

@mtshiba mtshiba marked this pull request as ready for review October 19, 2025 13:35
@MichaReiser
Copy link
Member

The hover changes look good to me but this PR also includes the changes of #20969

Are those changes necessary for this PR? If not, I suggest backing them out, so that we can merge this PR without having to wait for #20969

@mtshiba
Copy link
Contributor Author

mtshiba commented Oct 20, 2025

Changes that overlap with #20969 have been completely moved to #20969.

@MichaReiser MichaReiser enabled auto-merge (squash) October 20, 2025 17:28
@MichaReiser MichaReiser merged commit a7c38eb into astral-sh:main Oct 20, 2025
69 of 72 checks passed
@mtshiba mtshiba deleted the hover-variance branch October 20, 2025 17:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

server Related to the LSP server ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Display variance on hover over type variables

3 participants