Skip to content

union-annotation

Pythonstyleno fixdefault: offpython/ruff

Reports a typing.Union[...] subscript when the target_version has X | Y (3.10 and later).

Union[X, Y] is the same type as X | Y, which needs no import and reads like the other uses of |.

To fix, write X | Y.

Reported
from typing import Union
x: Union[int, str]
from typing import Optional
...
python:
lint:
rules:
union-annotation: warn # off (default), warn, error

Enabled by the presets: python/ruff.

Suppress one line with sudsy-disable-next-line union-annotation in a comment of the file’s language.

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
ruff UP007 full