Skip to content

type-alias-annotation

Pythonstyleno fixdefault: offpython/ruff

Reports X: TypeAlias = ... when the target_version has the type statement (3.12 and later).

type X = ... declares the alias as one, evaluates the right side lazily (so it can refer to later names) and needs no import of TypeAlias.

To fix, write type X = ....

Reported
...
pass
from typing import TypeAlias
X: TypeAlias = int
from typing import Generic, TypeVar
T = TypeVar("T")
...
python:
lint:
rules:
type-alias-annotation: warn # off (default), warn, error

Enabled by the presets: python/ruff.

Suppress one line with sudsy-disable-next-line type-alias-annotation in a comment of the file’s language.

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
ruff UP040 full