Since Python 3.12 the keyword type
is used to defined type aliases. It replaces the following construct:
from typing import TypeAlias, TypeVar
_T = TypeVar("_T")
MyTypeAlias: TypeAlias = set[_T]
Using the type
statement to define type aliases allows for a more concise code and thus better readability. This also makes it
possible to declutter the code, as imports from the typing
module (TypeAlias
and TyperVar
) can be removed.
type MyTypeAlias[T] = set[T]
Exceptions
This rule will only raise an issue when the Python version of the analyzed project is set to 3.12 or higher.