Skip to content

fix support creation of union from generic class constructor #1134#4152

Open
asukaminato0721 wants to merge 1 commit into
facebook:mainfrom
asukaminato0721:1134
Open

fix support creation of union from generic class constructor #1134#4152
asukaminato0721 wants to merge 1 commit into
facebook:mainfrom
asukaminato0721:1134

Conversation

@asukaminato0721

@asukaminato0721 asukaminato0721 commented Jul 15, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fixes #1134

Generic constructors now expand union arguments against union type hints and union successful specializations, and all expansions must match, preventing unsafe mixed-argument cases.

Test Plan

add test

@github-actions

Copy link
Copy Markdown

Diff from mypy_primer, showing the effect of this PR on open source code:

rotki (https://github.com/rotki/rotki)
- ERROR rotkehlchen/api/services/transactions.py:474:36-478:14: `dict[CHAINS_WITH_TRANSACTIONS_TYPE, list[BTCAddress | ChecksumAddress | SolanaAddress | SubstrateAddress]]` is not assignable to variable `blockchain_addresses` with type `dict[CHAINS_WITH_TRANSACTIONS_TYPE, ListOfBlockchainAddresses]` [bad-assignment]

@NathanTempest NathanTempest left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Really nice work @asukaminato0721 and I like that it reuses the existing ArgsExpander, gates on MAX_CALL_HINT_WIDTH, and tries the unexpanded path first for the common case. The mypy_primer result is a great signal: it removes a real false positive in rotki with no new errors. And the negative Pair(x, y) test is exactly the case I'd worry about correctly rejecting the mixed-argument union is the right call.

Since this is core constructor-specialization semantics, I'm looping in @stroxler to sign off on the "every expansion must match a union member" rule across the trickier interactions, constrained TypeVars, init overloads, and hints like A[int] | A[str] | None. Assuming that's sound, this looks ready.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

support creation of union from generic class constructor

3 participants