I have a class split into mixins:
class MyObject(MyObjectFilesMixin, MyObjectProcessingMixin, ...):
def __init__(self, value):
self.value = self.preprocess(value)
A mixin looks like this:
class MyObjectFilesMixin:
def load_from_file(cls, filename):
return ...
Now I'd like to add typing to the class and mixins:
class MyObjectFilesMixin:
def load_from_file(cls, filename: str) -> MyObject:
return ...
class MyObjectProcessingMixin:
def preprocess(self: MyObject, value: bytes):
return value # logic is omitted
def append(self: MyObject, other: MyObject):
self.value += other.value
But it leads to cyclic links. Of course I can create some MyObjectBase (following dependency inversion principle), so that MyObject will also inherit this class, and mixins will use it as argument/return type, but this will lead to wrong types anyway. Is it possible to fix??
I miss so much header+source files from C++