[ty] Resolve type aliases in filter_union method#22989
Merged
Conversation
Typing conformance resultsNo changes detected ✅ |
|
|
| Lint rule | Added | Removed | Changed |
|---|---|---|---|
invalid-assignment |
0 | 6 | 2 |
invalid-parameter-default |
0 | 0 | 7 |
invalid-argument-type |
0 | 2 | 2 |
invalid-return-type |
0 | 0 | 4 |
type-assertion-failure |
0 | 2 | 0 |
| Total | 0 | 10 | 15 |
This change modifies `filter_union` to resolve type aliases before checking if the type is a union. This allows `filter_union` to properly handle cases where a type alias resolves to a union type. With this change, the explicit `resolve_type_alias` call in `bind.rs` (added in #22988) is now redundant and has been removed. Added additional test cases for union type aliases with: - TypedDict dict literal inference - TypedDict dict() call inference - Set literal inference https://claude.ai/code/session_01Fsp2dSw6mnTBV1M2Fnf6gt
d6cc664 to
620916c
Compare
Contributor
Author
|
@ibraheemdev You'd mentioned this might break the current constraint solver, but if so it doesn't seem to show up in tests or in ecosystem? Is there some particular breakage you were thinking of that I should test for? |
ibraheemdev
approved these changes
Jan 30, 2026
Member
ibraheemdev
left a comment
There was a problem hiding this comment.
I was thinking that eagerly resolving type aliases would change our behavior in this example:
type X[T] = list[T] | None
def _(x: X[int]):
reveal_type(x) # revealed: `list[T] | None`But it looks like we already reveal the value of the type alias instead of the type alias itself, so this seems fine.
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
Update the
filter_unionmethod to resolve type aliases before checking if a type is a union. This ensures that union filtering works correctly when the type is a type alias that resolves to a union, not just direct union types.Test Plan
Added tests exercising various uses of
filter_unionthat fail without this fix.