Open
Description
Test env:
- mypy 0.670
- Python 3.7.2
Test code
from typing import List, Union
def f(x: Union[int, List[int]]) -> None: # `TypeVar` can fix it
x + x
Run mypy with default option, will get
a.py:5: error: Unsupported operand types for + ("int" and "List[int]")
a.py:5: error: Unsupported operand types for + ("List[int]" and "int")
a.py:5: note: Both left and right operands are unions
But actually, both left and right operands are same variable. Only int + int
or List[int] + List[int]
here. It seems like mypy does not consider object identity. And I'm not sure this is a bug, because above code is meaningless.