Skip to the content.

Type Hint for Type Alias

Recipes

# Python 3.12+

type Vector = list[float]
type Point[T] = tuple[T, T]
type IntOrStrSequence[T: (int, str)] = Sequence[T]  # 带约束的 TypeVar
type IntFunc[**P] = Callable[P, int]  # ParamSpec
# Python 3.11-

from typing import TypeAlias

Vector: TypeAlias = list[float]

More Details

References