[ty] Only prefer declared types in non-covariant positions#22068
Merged
ibraheemdev merged 1 commit intomainfrom Dec 19, 2025
Merged
[ty] Only prefer declared types in non-covariant positions#22068ibraheemdev merged 1 commit intomainfrom
ibraheemdev merged 1 commit intomainfrom
Conversation
Diagnostic diff on typing conformance testsNo changes detected when running ty on typing conformance tests ✅ |
|
649efd4 to
ad842fd
Compare
|
| Lint rule | Added | Removed | Changed |
|---|---|---|---|
invalid-return-type |
4 | 1 | 22 |
invalid-assignment |
0 | 0 | 23 |
invalid-argument-type |
6 | 4 | 10 |
no-matching-overload |
6 | 3 | 0 |
possibly-missing-attribute |
2 | 6 | 0 |
type-assertion-failure |
2 | 1 | 2 |
unused-ignore-comment |
3 | 0 | 0 |
non-subscriptable |
1 | 0 | 0 |
unsupported-operator |
0 | 1 | 0 |
| Total | 24 | 16 | 57 |
Member
Author
|
This seems to have a mixed ecosystem impact, which is somewhat unavoidable given any heuristic. Given that the impact is relatively small, and this becomes more important after #21930 (where we are able to infer a lot more type context from covariant types), I'm going to go ahead and merge this. Some of the regressions may also be improved by the new constraint solver. |
Member
|
That was my conclusion from skimming through the ecosystem diff too, yeah |
mtshiba
added a commit
to mtshiba/ruff
that referenced
this pull request
Dec 23, 2025
mtshiba
added a commit
to mtshiba/ruff
that referenced
this pull request
Dec 23, 2025
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The following snippet currently errors because we widen the inferred type, even though
Xis covariant overT. IfTwas contravariant or invariant, this would be fine, as it would lead to an assignability error anyways.There are some cases where it is still helpful to prefer covariant declared types, but this error seems hard to fix otherwise, and makes our heuristics more consistent overall.