Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / Python

typing.TypeAlias

Mark an assignment as a type alias for static analysis.

Version: Python 3.14; repository image, production runtime not attested

Syntax

Rows: TypeAlias = list[int]

Mark an assignment as a type alias for static analysis.

The assigned value remains the right-hand side at runtime, so this spelling does not create a distinct type or validate values. TypeAlias is deprecated since Python 3.12 in favor of the type statement.

The newer statement creates a TypeAliasType object whose value is available separately.

Examples

from typing import TypeAlias, TypeAliasType
Rows: TypeAlias = list[int]
type NewRows = list[int]
print(Rows == list[int], isinstance(Rows, TypeAliasType))
print(isinstance(NewRows, TypeAliasType), NewRows.__value__ == Rows)

Result

True False
True True

The newer statement creates a TypeAliasType object whose value is available separately.

Sources