Open
Description
Consider this example:
T = TypeVar('T')
S = TypeVar('S')
def add(x: List[T], y: List[S]) -> List[Union[T, S]]: ...
a: List[int]
b: List[str]
e: List[Union[int, str]] = add(a, b)
It fails on the last line with the following (I skip invariance notes):
error: Argument 1 to "add" has incompatible type "List[int]"; expected "List[Union[int, str]]"
error: Argument 2 to "add" has incompatible type "List[str]"; expected "List[Union[int, str]]"
If I remove the annotation for e
, everything works fine.
When previously working on the external context issues, I found that I don't like how constrains for unions against unions are inferred (not that they are wrong, just counterintuitive). For example, Union[T, S] <: Union[str, int]
infers T < : Union[str, int] and S <: Union[str, int]
, which is technically fine, but leads to errors like above.
This blocks #5873