Python Typehints
ab Python 3.10 PEP 604 – Allow writing union types as X | Y
Standard Typen
int str …
Benutzerdefinierte Typen
Check
from typing import NewType RGB = NewType("RGB", tuple[int, int, int])
Check
from typing import TypeVar TypeVar ..... # < 3.12
Generische Typen
def funktion[T](items: list[T]) -> T: # ab 3.12
Notizen
ab Python 3.5 (PEP 484 – Type Hints)
Any, Union, Tuple, Callable TypeVar, Generic
Dict, List
<neuer Typ> = NewType('<neuer Name>', int)