Abstract class + mixin + multiple inheritance in python Abstract class + mixin + multiple inheritance in python python python

Abstract class + mixin + multiple inheritance in python


Shouldn't the inheritance be the other way round? In the MRO foo currently comes before bar_for_foo_mixin, and then rightfully complains. With class myfoo(bar_for_foo_mixin, foo) it should work.

And I am not sure if your class design is the right way to do it. Since you use a mixin for implementing bar it might be better not to derive from foo and just register it with the 'foo' class (i.e. foo.register(myfoo)). But this is just my gut feeling.

For completeness, here is the documentation for ABCs.


i think (tested in similar case) that reversing the baseclasses works:

class myfoo(bar_for_foo_mixin, foo):    def __init__(self):        print "myfoo __init__ called"        self.bar()

so in the mro() it would find a concrete version of bar() before it finds the abstract one. No idea if this is actually what happens in the background though.

Cheers, Lars

PS: the code that worked in python 2.7 (python 3 has a different way to set metaclasses) was:

class A(object):    __metaclass__ = abc.ABCMeta    @abc.abstractmethod    def do(self):        passclass B(object):    def do(self):        print "do"class C(B, A):    passc = C()