Inhaltsverzeichnis

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