Open Naddiseo opened 5 years ago
Yeah, this comes up every once in a while. There might be an existing issue but I couldn't immediately find it. You are correct that this would be difficult to support, especially considering that this happens pretty rarely.
Naively this may look like a duplicate of https://github.com/python/mypy/issues/6478, but I think this is different (and harder). In that issue we would essentially check the same expression multiple times (for every item in the relevant union). Here however we need to type-check the rest of the function multiple times.
See also https://github.com/python/mypy/issues/5579 for yet another aspect. Sometimes binder can infer restrictions for the "parent" expression.
I'm not sure how to entitle this, but I think it's a dependent type.
def x() -> Union[Tuple[int, int], Tuple[str, str]]: ...
a, b = x()
if isinstance(b, int): reveal_type(a) # can only be int but is reported as Union[int, str]