Closed
Description
Hello,
the following code:
from typing import List, Union
import sys
p : Union[int, List[int]] = 1 if len(sys.argv) else []
incorrectly generates the following error:
t.py:3: error: Incompatible types in assignment (expression has type "Union[int, List[<nothing>]]", variable has type "Union[int, List[int]]")
Adding an integer in the list makes the error disappear. I first observed this issue with a dictionary:
from typing import Dict, Union
import sys
p : Union[int, Dict[int, int]] = 1 if len(sys.argv) else {}
Error:
t.py:3: error: Incompatible types in assignment (expression has type "Union[int, Dict[<nothing>, <nothing>]]", variable has type "Union[int, Dict[int, int]]")
It seems <nothing>
should be matched with any type in type parameters in unions.