Skip to content

type-var-name-variance

Pythonstyleno fixdefault: offpython/ruff

Reports a TypeVar with covariant=True whose name does not end in _co, or with contravariant=True and a name that does not end in _contra.

The suffixes are the convention of the typing documentation and of the standard library stubs. A reader sees the variance in every annotation that uses the name, without finding the declaration.

To fix, rename the variable with the suffix.

Reported
...
return True
from typing import TypeVar
T = TypeVar("T", covariant=True)
python:
lint:
rules:
type-var-name-variance: warn # off (default), warn, error

Enabled by the presets: python/ruff.

Suppress one line with sudsy-disable-next-line type-var-name-variance 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 PLC0105 full