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

Unsupported operand types for + ("Union[int, float]" and "int") #21

Closed
wsanchez opened this issue Dec 16, 2016 · 2 comments
Closed

Unsupported operand types for + ("Union[int, float]" and "int") #21

wsanchez opened this issue Dec 16, 2016 · 2 comments

Comments

@wsanchez
Copy link
Owner

wsanchez commented Dec 16, 2016

mypy is complaining about math.py thusly:

src/sample_klein_app/application/math.py: note: In member "add" of class "Application":
src/sample_klein_app/application/math.py:54: error: Unsupported operand types for + ("Union[int, float]" and "int")
src/sample_klein_app/application/math.py: note: In member "subtract" of class "Application":
src/sample_klein_app/application/math.py:70: error: Unsupported operand types for - ("Union[int, float]" and "int")
src/sample_klein_app/application/math.py: note: In member "multiply" of class "Application":
src/sample_klein_app/application/math.py:85: error: Unsupported operand types for * ("Union[int, float]" and "int")
src/sample_klein_app/application/math.py: note: In member "divide" of class "Application":
src/sample_klein_app/application/math.py:101: error: Unsupported operand types for / ("Union[int, float]" and "int")
@wsanchez
Copy link
Owner Author

What's going on, I think, is that we have:

def numberify(string: str) -> Union[int, float]:
    ...

And the math methods are doing something like:

self.numberify(a) + self.numberify(b)

And mypy thinks that the arithmetic operators don't like Union[int, float] and int, even though it's totally OK to operate on float and int combinations:

>>> 1.0 + 1
2.0

A confusing aspect for me is that int is part of the complaint at all; this is actually a Union[int, float]s being added to another Union[int, float], not an int.

@wsanchez
Copy link
Owner Author

Looks like a mypy bug: python/mypy#2128

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

No branches or pull requests

1 participant