Typing and Generics

typing.TypeAliasType

Runtime object representing a named type alias, including aliases created by the type statement (3.12+). Inspect __value__ and __type_params__; statement aliases evaluate their values lazily. It is not an instance validator.

Formal Syntax & Structure

python syntaxpython
typing.TypeAliasType(name, value, *, type_params=())

Parameters & Attributes

NameTypeDescription
namestrName of the alias.
valueobjectAliased type expression.
type_paramstupleDeclared type parameters.

Return Value

TypeAliasType

Typing construct or runtime result as described; static typing rules are not runtime validation.

Working Example

Example Snippetpython
from typing import TypeAliasType
type Pair[T] = tuple[T, T]print((isinstance(Pair, TypeAliasType), Pair.__name__, len(Pair.__type_params__)))
Python Reference