[ty] Support solving generics involving PEP 695 type aliases#22678
Merged
ibraheemdev merged 1 commit intoastral-sh:mainfrom Jan 21, 2026
Merged
[ty] Support solving generics involving PEP 695 type aliases#22678ibraheemdev merged 1 commit intoastral-sh:mainfrom
ibraheemdev merged 1 commit intoastral-sh:mainfrom
Conversation
Typing conformance resultsNo changes detected ✅ |
|
|
| Lint rule | Added | Removed | Changed |
|---|---|---|---|
invalid-await |
0 | 0 | 6 |
invalid-return-type |
1 | 4 | 1 |
invalid-argument-type |
1 | 2 | 0 |
unused-ignore-comment |
2 | 0 | 0 |
| Total | 4 | 6 | 7 |
ibraheemdev
reviewed
Jan 21, 2026
ibraheemdev
reviewed
Jan 21, 2026
| reveal_type(head(["a", "b"])) # revealed: str | ||
|
|
||
| d: dict[str, int] = {"a": 1} | ||
| reveal_type(get_value(d, "a")) # revealed: int |
Member
There was a problem hiding this comment.
Can we also add tests for the reverse direction, e.g.,
type MyList[T] = list[T]
def head[T](list: list[T]) -> T:
return list[0]
def _(x: MyList[int]):
reveal_type(head(x)) # revealed: intThis test fails on main.
Member
|
Interestingly there seems to be no ecosystem impact (I believe most of the changes are spurious), but this should be good to land after the added test. A rebase should also fix the failing benchmark job. |
Add support for type variable inference when a PEP 695 type alias is used as a function parameter or argument type. Changes: - Formal type alias expansion: Add match arm to expand formal type aliases so their underlying structure (e.g., list[T]) is visible for matching - Actual type alias expansion: Add match arm at the end to expand actual type aliases while preserving alias identity for direct TypeVar matches Test Plan: - Add tests for solving generics with type alias parameters - Add test for reverse direction (type alias as argument type) Closes astral-sh/ty#1851
4f050fb to
6782dfc
Compare
Member
|
Thanks! |
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
Fixes type variable inference when a PEP 695 type alias is used as a function parameter.
Before:
After: Correctly infers
intby expandingMyList[T]tolist[T]during solving.Changes in
generics.rs:reveal_type()and literal promotionListOfPairs[T] = list[Pair[T]]The early/late expansion asymmetry is intentional: formal needs structural visibility; actual needs identity preservation.
Test Plan
aliases.mdcovering simple, nested, and union alias casesCloses astral-sh/ty#1851