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

Closed
campkeith opened this issue Jul 21, 2018 · 1 comment
Closed

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

campkeith opened this issue Jul 21, 2018 · 1 comment

Comments

@campkeith
Copy link

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.

@campkeith
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant