optional-annotation
What it does
Section titled “What it does”Reports a typing.Optional[...] subscript when the target_version has X | Y (3.10 and later).
Why it matters
Section titled “Why it matters”Optional[X] is a name for X | None, which the newer syntax writes without an import and in the same form as other unions. The name also suggests a parameter that may be left out, which it is not.
To fix, write X | None.
Example
Section titled “Example”...
from typing import Optionalx: Optional[int]
...Configuration
Section titled “Configuration”python: lint: rules: optional-annotation: warn # off (default), warn, errorEnabled by the presets: python/ruff.
Suppress one line with sudsy-disable-next-line optional-annotation in a comment of the file’s language.
Upstream equivalents
Section titled “Upstream equivalents”The same check in other tools; Sudsy reports what each upstream rule reports.
| Tool | Rule | Match |
|---|---|---|
| ruff | UP045 |
full |