BSK-E0128 error

``TypeVar`` default referential violations

PEP 696 defines rules for when a TypeVar default references another TypeVar:

1. **Ordering**: The referenced TypeVar must appear before the referencing TypeVar in Generic.... 2. **Scope**: A TypeVar default must not reference TypeVarar from an outer class scope. 3. **Bound/constraint compatibility**: When TypeVar T2 defaults to TypeVar T1, T1's bound must be a subtype of T2's bound, and T2's constraints (if any) must be a superset of T1's constraints.

from typing import TypeVar, Generic

S1 = TypeVar("S1")
S2 = TypeVar("S2", default=S1)

Start2T = TypeVar("Start2T", default="StopT")
Stop2T = TypeVar("Stop2T", default=int)
class slice2(Generic[Start2T, Stop2T]): ...   # E: bad ordering

class Foo3(Generic[S1]):
    class Bar2(Generic[S2]): ...              # E: outer scope

Y1 = TypeVar("Y1", bound=int)
Invalid2 = TypeVar("Invalid2", float, str, default=Y1)  # E

How to handle it

Every rule is on by default — strict is the default, not a cage. You can dial BSK-E0128 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/BSK-E0128