|
I saw the discussion at clarifying the multiple inheritance non-support #1242 and note the branch
When I try to define the class I understand that I could probably get this to work with a trampoline but it would be much simpler to be able to attach extra methods to a class in pure Python. This is a stumbling block when porting a pybind11 project to nanobind. |
Replies: 2 comments 3 replies
|
You don't need a trampoline just to add Python methods to class Mixed(Child):
def extra(self):
return self.value() + 1 # value() is a bound C++ methodI checked this with a small The restriction is specifically the two direct bases in For a small mixin containing ordinary helper methods, assigning them on the single subclass can be enough: class Mixed(Child):
extra = Mixin.extraThat last workaround doesn't preserve mixin inheritance: avoid it if the methods depend on zero-argument |
|
Thanks for your reply and sorry for introducing confusion re the trampoline, that is not what I need. Your simple inheritance example works but is not sufficient for our use case. We have many classes that require the mixins (and potentially more than one mixin). It would be a significant refactor and degradation of the code if we had to bind the mixins to e.g. Apart from now being out-of-date, the |
@oghm2 Please see commit 32c595d.