I get unexpected mypy
errors when using builtin binary operations on variables of type TypeVar('T', bound=int|float)
.
Here is a minimal example:
import typing
T = typing.TypeVar('T', bound=typing.Union[int, float])
def less_than(x: T, y: T) -> bool:
return x < y
mypy
gives me the following error:
test.py:6: error: Unsupported operand types for < ("int" and "T")
Why do I get that error?
On a side note: mypy
doesn't complain if I use T = typing.Union[int, float]
or T = typing.TypeVar('T', int, float)
.