Given the following code, I'd expect both a.x
and a.y
to be declared during instantiation. When class P
doesn't inherit from Protocol
both assertions pass. In the debugger, it doesn't seem that class P
's constructor is ever being ran. I suspect this has to do with the MRO in some way, but my main question is whether I can still use super()__init__()
while still having my base class inherit from Protocol
from typing import Protocol
class P(Protocol):
y: str
def __init__(self, y: str) -> None:
self.y = y
class A(P):
x: str
def __init__(self, x: str, y: str) -> None:
self.x = x
super().__init__(y=y)
a = A("x", "y")
assert a.x == "x"
assert a.y == "y" # AttributeError: 'A' object has no attribute 'y'