For this code:
from typing import Union
def add(a: Union[float, int], b: Union[float, int]) -> float:
return a + b
The error I get is:
% mypy --version
mypy 0.620
% mypy foo.py
foo.py:4: error: Unsupported operand types for + ("Union[float, int]" and "Union[float, int]")
If I declare either parameter as just an int
or a float
(and leave the other parameter unchanged) then the error goes away.
According to the documentation, it seems that Union[float, int]
should be equivalent to float
. So the simple solution seems to be to declare both parameters as float
, but I would expect mypy to figure this out.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4