---
source: crates/ruff_linter/src/rules/flake8_pyi/mod.rs
---
PYI026 [*] Use `typing.TypeAlias` for type alias, e.g., `NewAny: TypeAlias = Any`
 --> PYI026.pyi:3:1
  |
1 | from typing import Literal, Any
2 |
3 | NewAny = Any
  | ^^^^^^
4 | OptionalStr = typing.Optional[str]
5 | Foo = Literal["foo"]
  |
help: Add `TypeAlias` annotation
  |
  - from typing import Literal, Any
1 + from typing import Literal, Any, TypeAlias
2 |
  - NewAny = Any
3 + NewAny: TypeAlias = Any
4 | OptionalStr = typing.Optional[str]
  |

PYI026 [*] Use `typing.TypeAlias` for type alias, e.g., `OptionalStr: TypeAlias = typing.Optional[str]`
 --> PYI026.pyi:4:1
  |
3 | NewAny = Any
4 | OptionalStr = typing.Optional[str]
  | ^^^^^^^^^^^
5 | Foo = Literal["foo"]
6 | IntOrStr = int | str
  |
help: Add `TypeAlias` annotation
  |
  - from typing import Literal, Any
1 + from typing import Literal, Any, TypeAlias
2 |
3 | NewAny = Any
  - OptionalStr = typing.Optional[str]
4 + OptionalStr: TypeAlias = typing.Optional[str]
5 | Foo = Literal["foo"]
  |

PYI026 [*] Use `typing.TypeAlias` for type alias, e.g., `Foo: TypeAlias = Literal["foo"]`
 --> PYI026.pyi:5:1
  |
3 | NewAny = Any
4 | OptionalStr = typing.Optional[str]
5 | Foo = Literal["foo"]
  | ^^^
6 | IntOrStr = int | str
7 | AliasNone = None
  |
help: Add `TypeAlias` annotation
  |
  - from typing import Literal, Any
1 + from typing import Literal, Any, TypeAlias
2 |
3 | NewAny = Any
4 | OptionalStr = typing.Optional[str]
  - Foo = Literal["foo"]
5 + Foo: TypeAlias = Literal["foo"]
6 | IntOrStr = int | str
  |

PYI026 [*] Use `typing.TypeAlias` for type alias, e.g., `IntOrStr: TypeAlias = int | str`
 --> PYI026.pyi:6:1
  |
4 | OptionalStr = typing.Optional[str]
5 | Foo = Literal["foo"]
6 | IntOrStr = int | str
  | ^^^^^^^^
7 | AliasNone = None
  |
help: Add `TypeAlias` annotation
  |
  - from typing import Literal, Any
1 + from typing import Literal, Any, TypeAlias
2 |
3 | NewAny = Any
4 | OptionalStr = typing.Optional[str]
5 | Foo = Literal["foo"]
  - IntOrStr = int | str
6 + IntOrStr: TypeAlias = int | str
7 | AliasNone = None
  |

PYI026 [*] Use `typing.TypeAlias` for type alias, e.g., `AliasNone: TypeAlias = None`
 --> PYI026.pyi:7:1
  |
5 | Foo = Literal["foo"]
6 | IntOrStr = int | str
7 | AliasNone = None
  | ^^^^^^^^^
8 |
9 | NewAny: typing.TypeAlias = Any
  |
help: Add `TypeAlias` annotation
  |
  - from typing import Literal, Any
1 + from typing import Literal, Any, TypeAlias
2 |
--------------------------------------------------------------------------------
6 | IntOrStr = int | str
  - AliasNone = None
7 + AliasNone: TypeAlias = None
8 |
  |

PYI026 [*] Use `typing.TypeAlias` for type alias, e.g., `FLAG_THIS: TypeAlias = None`
  --> PYI026.pyi:17:5
   |
16 | class NotAnEnum:
17 |     FLAG_THIS = None
   |     ^^^^^^^^^
18 |
19 | # these are ok
   |
help: Add `TypeAlias` annotation
   |
   - from typing import Literal, Any
1  + from typing import Literal, Any, TypeAlias
2  |
--------------------------------------------------------------------------------
16 | class NotAnEnum:
   -     FLAG_THIS = None
17 +     FLAG_THIS: TypeAlias = None
18 |
   |
