Specifying a type to be a List of numbers (ints and/or floats)?

Viewed 40034

How do I specific a function can take a list of numbers which can be ints or floats?

I tried making a new type using Union like so:

num = Union[int, float]

def quick_sort(arr: List[num]) -> List[num]:
    ...

However, mypy didn't like this:

 quickSortLomutoFirst.py:32: error: Argument 1 to "quickSortOuter" has
 incompatible type List[int]; expected List[Union[int, float]]  

Is there a Type that encompasses ints and floats?

2 Answers
Related