Consider using https://github.com/astral-sh/ruff as it supports this check and a lot more
Flake8 plugin to enforce the new Union and Optional annotation syntax defined in PEP 604.
Union[X, Y] = X | Y
Optional[X] = X | NoneNote that it's impossible to use forward references in the new syntax, like this:
"X" | intsuch a case can be expressed as a string containing both union terms:
"X | int"pip install flake8-new-union-types
or if you use poetry:
poetry add --dev flake8-new-union-types
- NU001 Use
Foo | Barsyntax instead of Union (PEP 604) - NU002 Use
Foo | Nonesyntax instead of Optional (PEP 604) - NU003 Present the whole expression as a string to annotate forward refs, e.g.
"int | Foo"(PEP 604)
There is no way to configure the plugin at the moment.