-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multiple Inheritance partial delegation #19
Comments
OK, I will give it a try |
@EDEADLINK you are probably misusing the library. |
Here is a simplified example of what I ended up doing. class Named(abc.ABC):
@abc.abstractmethod
def __init__(self, name="", **kwargs):
self._name = name
super().__init__(**kwargs)
@property
def name(self):
return self._name
class Invertible(abc.ABC):
@abc.abstractmethod
def invert(self):
pass
class abstract_interface(Named, Invertable):
@abc.abstractmethod
def some_method(self):
pass
def some_other_methods(self):
pass
...
# interface where most of the implementation is delegated
class interface(abstract_interface, metaclass=delegation("_delegate"):
def __init__(self, impl, **kwargs):
self._delegate = impl
super().__init__(**kwargs)
@abc.abstractmethod
def invert(self):
pass
# implementation of interface need only implement invert,
# because some_object implements the rest
class impl(interface):
def __init__(self, **kwargs):
super().__init__(library.some_object())
def invert(self):
...
return self The goal was to extend a library object. |
@EDEADLINK You don't need to call super() if your class inherits from an abstract base class which doesn't have init method (as it should, because it is an interface) |
First up super cool project. Takes most of the headache out of delegation.
I was wondering if in the case of multiple inheritance you could specify which class to delegate.
Say your class C inherits from A and B but only require that the delegate implements A.
Right now the only way that seems to work is to add all the methods of B to your Class C as abstract methods, or turn of validation completely.
More concretely I would like to do this:
Without having to write:
Or turn of validation.
Alternatively making this work would be equally nice
I don't know how difficult either thing is because metaclasses and inheritance gives me headaches, but it feels like it should be possible.
The text was updated successfully, but these errors were encountered: