BSK-E0146
error
Protocol class object violations
Detects two related violations involving Protocol classes and class objects:
1. A Protocol class itself is passed/assigned where typeProto is expected. Only concrete (non-Protocol) subtypes may be used.
2. A class object is assigned to a variable typed as a Protocol instance, but the class does not structurally satisfy the protocol when treated as an object (i.e. class-level access to protocol members gives incompatible types).
class Proto(Protocol):
def meth(self) -> int: ...
class Concrete:
def meth(self) -> int: return 42
def fun(cls: type[Proto]) -> int:
return cls().meth()
fun(Proto) # E0146 — Protocol class itself passed to type[Proto]
fun(Concrete) # OK
var: type[Proto]
var = Proto # E0146 — Protocol class assigned to type[Proto]
var = Concrete # OK
pa1: ProtoA1 = ConcreteA # E0146 — class object can't satisfy instance protocol
pa2: ProtoA2 = ConcreteA # OK — protocol uses _self/self pattern
How to handle it
Every rule is on by default — strict is the default, not a cage. You can dial
BSK-E0146 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-E0146