BSK-E0078
error
Self type violations in generics
This rule detects two kinds of Self type violations:
1. **Return type mismatch**: A method (or classmethod) annotated -> Self returns a concrete class constructor call (e.g. return Shape()) instead of self, cls(), or another Self-compatible expression. In a subclass, Self resolves to the subclass type, so returning the parent class constructor is a type error.
2. **Self is not subscriptable**: Self cannot be parameterized (e.g. Selfint). It already captures the full generic specialization of the enclosing class.
from typing import Self
class Shape:
def method2(self) -> Self:
return Shape() # E — should return self, not Shape()
@classmethod
def cls_method2(cls) -> Self:
return Shape() # E — should return cls(), not Shape()
class Container(Generic[T]):
def foo(self, other: Self[int]) -> None: # E — Self is not subscriptable
pass
How to handle it
Every rule is on by default — strict is the default, not a cage. You can dial
BSK-E0078 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-E0078