protocols_runtime_checkable_2
error
Protocol isinstance/issubclass violations
Per PEP 544: - A protocol can be used as the second argument to isinstance() or issubclass() **only** if it is decorated with @runtime_checkable. - issubclass() can only be used with **non-data** protocols (protocols that define only methods, not data attributes). - Type checkers should reject an isinstance() or issubclass() call if there is an unsafe overlap between the type of the first argument and the protocol.
from typing import Protocol, runtime_checkable
class Proto1(Protocol):
name: str
@runtime_checkable
class Proto2(Protocol):
name: str
def method(self) -> int: ...
isinstance(x, Proto1) # E — not @runtime_checkable
issubclass(x, Proto2) # E — data protocol in issubclass
isinstance(Concrete(), Proto3) # E — unsafe overlap
How to handle it
Every rule is on by default — strict is the default, not a cage. You can dial
protocols_runtime_checkable_2 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/protocols_runtime_checkable_2