Derived from the pyupgrade linter.
Fix is always available.
What it does#
Checks for use of
TypeAlias annotation for declaring type aliases.
Why is this bad?#
type keyword was introduced in Python 3.12 by PEP 695 for defining
type aliases. The
type keyword is easier to read and provides cleaner
support for generics.
PEP 695 uses inferred variance for type parameters, instead of the
contravariant keywords used by
TypeParam variables. As
such, rewriting a
TypeParam variable to a
type alias may change its
TypeParam variables, PEP 695-style
type aliases cannot be used
at runtime. For example, calling
isinstance on a
type alias will throw
TypeError. As such, rewriting a
TypeParam via the
type keyword will
cause issues for parameters that are used for such runtime checks.