Python Typ-Hinweise: die Angabe eines Typs aus einer Liste von zahlen (int und/oder Schwimmer)?

Wie kann ich eine bestimmte Funktion kann eine Liste von zahlen, die kann ints oder floats?

Ich habe versucht, eine neue Art der Verwendung von Union in etwa so:

num = Union[int, float]

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

Jedoch mypy nicht wie diese:

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

Ist es ein Typ, der umfasst ints und floats?

Schreibe einen Kommentar