type-alias-without-annotation (PYI026)
Derived from the flake8-pyi linter.
Fix is always available.
What it does
Checks for type alias definitions that are not annotated with
typing.TypeAlias
.
Why is this bad?
In Python, a type alias is defined by assigning a type to a variable (e.g.,
Vector = list[float]
).
It's best to annotate type aliases with the typing.TypeAlias
type to
make it clear that the statement is a type alias declaration, as opposed
to a normal variable assignment.
Example
Use instead:
Availability
Because this rule relies on the third-party typing_extensions
module for Python versions
before 3.10, its diagnostic will not be emitted, and no fix will be offered, if
typing_extensions
imports have been disabled by the lint.typing-extensions
linter option.