generics_variance_inference
error
TypeVar scoping violation
Detects uses of TypeVar instances outside their valid scope:
1. A nested class inside a generic class using the outer class's TypeVar in its base classes or body (the outer class's type params don't cover the inner class scope). 2. A class nested inside a generic function re-using the function's TypeVar in Generic.... 3. A TypeVar used in a module-level expression (subscript call like listT()). 4. A method call on a generic class instance where the argument type does not match the substituted TypeVar type (e.g., a: MyClassint, calling a.meth('str') when meth expects T which is bound to int).
Per PEP 484: "A generic class nested in another generic class cannot use the same type variables."
How to handle it
Every rule is on by default — strict is the default, not a cage. You can dial
generics_variance_inference 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/generics_variance_inference