Glossary

Type Alias

A type alias is a name assigned to a complex type annotation, making it easier to read and reuse. In simple form, you write Vector = list[float] and then use Vector in annotations. Python 3.12 introduced the type statement for explicit aliases: type Vector = list[float], which creates a TypeAliasType object that tools can distinguish from regular variable assignments.

Type aliases are most useful when annotations become long or repetitive. Instead of writing dict[str, list[tuple[int, float]]] throughout your code, you define type Matrix = dict[str, list[tuple[int, float]]] once and use Matrix everywhere. This improves readability without changing the runtime behaviour — aliases are purely a type-checking and documentation tool.

Before Python 3.12, typing.TypeAlias (PEP 613) provided an explicit annotation: Vector: TypeAlias = list[float]. The new type statement is preferred because it is lazily evaluated (avoiding forward reference issues), creates a proper TypeAliasType, and has cleaner syntax. Type aliases are complementary to NewType, which creates a distinct type for the checker (unlike aliases, which are transparent).

Related terms: Type Hint, Generic

Discussed in:

This site is currently in Beta. Please email Chris Paton (cpaton@gmail.com) with any suggestions, questions or comments.