Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Union[float, int] is unsupported type for binary math operators #5381

campkeith opened this Issue Jul 21, 2018 · 1 comment


None yet
1 participant
Copy link

campkeith commented Jul 21, 2018

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 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.


This comment has been minimized.

Copy link

campkeith commented Jul 21, 2018

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...)

@campkeith campkeith closed this Jul 21, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.