specialtypes_never_2
error
Never type compatibility violations
Detects type compatibility errors involving the Never bottom type:
1. Assigning a parameter typed ContainerNever to a local annotated ContainerT where T is not Never or Any (invariant violation) 2. Returning ClassCNever() from a function annotated -> ClassCU where the class's type parameter is invariant (not covariant)
from typing import Never, Any, Generic, TypeVar
T = TypeVar("T")
U = TypeVar("U")
def func(c: list[Never]):
v: list[int] = c # E0070 — list is invariant, list[Never] != list[int]
class ClassC(Generic[T]):
pass
def func2(x: U) -> ClassC[U]:
return ClassC[Never]() # E0070 — ClassC is invariant
How to handle it
Every rule is on by default — strict is the default, not a cage. You can dial
specialtypes_never_2 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/specialtypes_never_2