generics_type_erasure
error
Access to instance attribute on a class object
Instance attributes (annotations without ClassVar in the class body that lack a default value) exist only on instances, not on the class object itself. Accessing or assigning such attributes on the class (including parameterised generics like Nodeint) is an error.
from typing import Generic, TypeVar
T = TypeVar("T")
class Node(Generic[T]):
label: T
Node[int].label = 1 # E: instance attribute on class
Node[int].label # E
Node.label = 1 # E
Node.label # E
type(n1).label # E
How to handle it
Every rule is on by default — strict is the default, not a cage. You can dial
generics_type_erasure 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_type_erasure