You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
By clicking &ldquo
A41C
;Sign up for GitHub”, you agree to our terms of service and
privacy statement. We’ll occasionally send you account related emails.
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.
The text was updated successfully, but these errors were encountered:
Looks like this is the same as #2128 (this was hard to find as none of my search queries seem to pull it up; I ran into it looking at a thread for a related issue...)
For this code:
The error I get is:
If I declare either parameter as just an
int
or afloat
(and leave the other parameter unchanged) then the error goes away.According to the documentation, it seems that
Union[float, int]
should be equivalent tofloat
. So the simple solution seems to be to declare both parameters asfloat
, but I would expect mypy to figure this out.The text was updated successfully, but these errors were encountered: