A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/python/mypy/pull/5381 below:

Union[float, int] is unsupported type for binary math operators · Issue #5381 · python/mypy · GitHub

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