Distribute return type over union #2047
Unanswered
randolf-scholz
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Inspired by microsoft/pyright#10673, I looked at this simple example: Code sample in pyright playground
It feels like the revealed type is not actually what we want here. The desirable inference is imo
list[str] | list[int]
.Is there simple way to annotate
listify
to make the return type distribute over unions, or is this a general type-checker limitation?What seems to happen here is that we assign
Sequence[str] | Sequence[int] <: Sequence[str | int] = Sequence[T]
, so we pickT = int | str
. However, in principle wouldn't it be more precise if the type checker, when seeing aUnionType
as an argument, passes every member separately and yields theUnionType
of the individual return types?I guess with multiple arguments this runs into combinatoric explosion...
Beta Was this translation helpful? Give feedback.
All reactions