Open
Description
from typing import Union
x = 0 # type: Union[int, str]
reveal_type(x) # Revealed type is 'Union[builtins.int, builtins.str]'
x = 0
reveal_type(x) # Revealed type is 'builtins.int'
This means if you want to declare a union and then immediately use it as one specific member, you'll have an awkward time. For example:
x = "foo" # type: Optional[str]
x + "bar" # E: Unsupported operand types for + ("Union[str, None]" and "str")
To be consistent with other assignments, we should add types to the binder on initial assignment. I think a number of Union/Optional tests depend on the current behavior, so those will need to be updated.