Closed
Description
While debugging a more complicated issue, I reduced it to this:
from typing import Tuple, Union
Pair = Tuple[int, int]
Variant = Union[int, Pair]
def tuplify(v: Variant) -> None:
if not isinstance(v, tuple):
v = (v, v)
print(v[0], v[1])
mypy running on this example detects an error on the print
line saying:
foo.py:10: error: Value of type None is not indexable
For some reason it says that the value of v
has type None
. I understand why the checker may not be able to follow the negative isinstance check, but I expected the error to say something like Value of type Union[...] is not indexable
.