protocols_variance error

Protocol variance violation

Detects when a Protocol class declares TypeVars with incorrect variance based on how they are used in method signatures:

- A TypeVar used only in output positions (return types) should be covariant. - A TypeVar used only in input positions (parameters) should be contravariant. - A covariant TypeVar used in input position is a violation. - A contravariant TypeVar used in output position is a violation.

__init__ and __new__ methods are exempt from variance inference.

How to handle it

Every rule is on by default — strict is the default, not a cage. You can dial protocols_variance down per-file or per-path from your editor or pyproject.toml, or fix the code so it type-checks. See the Type System rules and the complete diagnostic reference.

Canonical URL: https://www.basilisk-python.dev/errors/protocols_variance