fix support creation of union from generic class constructor #1134#4152
fix support creation of union from generic class constructor #1134#4152asukaminato0721 wants to merge 1 commit into
Conversation
|
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
left a comment
There was a problem hiding this comment.
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.
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