protocols_subtyping
error
Protocol attribute tuple element type mismatch
When a class explicitly implements a Protocol and assigns to a self.attr in __init__ where attr is declared as tupleT1, T2, ... in the protocol, each element of the assigned tuple must have a compatible type. If a parameter used in the tuple has a different type than the corresponding element type in the protocol's annotation, Basilisk reports the mismatch.
from typing import Protocol
class RGB(Protocol):
rgb: tuple[int, int, int]
class Point(RGB):
def __init__(self, red: int, green: int, blue: str) -> None:
self.rgb = red, green, blue # E — 'blue' must be 'int'
How to handle it
Every rule is on by default — strict is the default, not a cage. You can dial
protocols_subtyping 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_subtyping