> ## Documentation Index
> Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Python Type Alias

A type alias is a user-defined identifier that serves as a static synonym for an existing type annotation. It is evaluated by static type checkers (such as mypy or pyright) as strictly equivalent to the underlying type, meaning it does not create a new distinct runtime class or subclass.

## Syntax Evolution

The implementation of type aliases in Python has evolved significantly across versions.

### Python 3.12+ (Modern Syntax)

Python 3.12 introduced the `type` soft keyword, which formally defines a type alias. This syntax creates an instance of `typing.TypeAliasType` at runtime and supports lazy evaluation, allowing for forward references without string literals.

```python theme={"dark"}
type Point = tuple[float, float]
type NestedDict = dict[str, dict[str, int]]
```

### Python 3.10 - 3.11 (`TypeAlias`)

To disambiguate type aliases from standard global variable assignments, Python 3.10 introduced the `TypeAlias` annotation in the `typing` module.

```python theme={"dark"}
from typing import TypeAlias

Point: TypeAlias = tuple[float, float]
NestedDict: TypeAlias = dict[str, dict[str, int]]
```

### Pre-Python 3.10 (Legacy Syntax)

Historically, type aliases were created using standard variable assignment. While still supported, this approach lacks explicit intent for static analyzers.

```python theme={"dark"}
Point = tuple[float, float]
NestedDict = dict[str, dict[str, int]]
```

## Generic Type Aliases

Type aliases support generics, allowing them to accept type parameters.

### Python 3.12+ Generics

The `type` statement supports inline type parameters using square brackets, automatically scoping the type variables.

```python theme={"dark"}
type Matrix[T] = list[list[T]]
type Result[V, E] = V | E
```

### Pre-Python 3.12 Generics

Older versions require the explicit instantiation of `typing.TypeVar` objects.

```python theme={"dark"}
from typing import TypeVar, TypeAlias

T = TypeVar('T')
V = TypeVar('V')
E = TypeVar('E')

Matrix: TypeAlias = list[list[T]]
Result: TypeAlias = V | E
```

## Technical Characteristics

* **Equivalence:** A type alias is structurally identical to its target. If `type A = int`, a type checker will accept an `int` wherever `A` is expected, and vice versa. It is not a nominal type.
* **Lazy Evaluation (3.12+):** The right-hand side of a `type` statement is not evaluated when the module is loaded. It is evaluated only when the alias's `__value__` attribute is accessed, enabling recursive type definitions natively.
* **Introspection:** In Python 3.12+, type aliases can be inspected at runtime via the `__name__`, `__type_params__`, and `__value__` attributes of the `TypeAliasType` object.

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor Python Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
