I want to define an interface for a data class, but leave open the way the data is stored. To this end, I define a protocol A
for the interface and an implementation B
:
<code>class A(Protocol):
@property
def field(self):
...
@field.setter
def field(self, value):
...
class B(A):
@property
def field(self):
return ""
@field.setter
def field(self, value):
pass
</code>
<code>class A(Protocol):
@property
def field(self):
...
@field.setter
def field(self, value):
...
class B(A):
@property
def field(self):
return ""
@field.setter
def field(self, value):
pass
</code>
class A(Protocol):
@property
def field(self):
...
@field.setter
def field(self, value):
...
class B(A):
@property
def field(self):
return ""
@field.setter
def field(self, value):
pass
mypy
has no issues with this implementation, but PyCharm warns me that
<code>Type of 'field' is incompatible with 'A'
</code>
<code>Type of 'field' is incompatible with 'A'
</code>
Type of 'field' is incompatible with 'A'
Above approach was already proposed in this answer, but PyCharm doesn’t really like it.
How would I better write this?