An annotation uses Optional[X] or Union[X, Y] where X | None and X | Y say the same

tx0/python:legacy-union-syntaxstrictnotestyle

What it finds

Since Python 3.10, and in annotations of any version with from __future__ import annotations, unions are written with |: int | None reads like what it means and needs no import. Reported are Optional and Union from typing or typing_extensions in annotations of parameters, return values and variables. Stubs keep their style.

From the rule's source, legacy_union_syntax.rs.

Example from the rule's tests
from typing import Optional, Union  def find(name: Optional[str]) -> int | str:tx0 reports: Optional[X] is written X | None    value: Union[int, None] = Nonetx0 reports: Union[X, Y] is written X | Y    options = Optional[int]    return value or 0
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/python:legacy-union-syntax" = "note"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

# tx0: ignore[tx0/python:legacy-union-syntax] reason="..."

tx0 explain tx0/python:legacy-union-syntax shows the same in the terminal. Found a false positive? Report it.