Multiple inheritance - How to call method_x in InheritedBaseB from method_x in InheritedBaseA?

Carl Banks pavlovevidence at gmail.com
Wed Sep 9 20:21:42 CEST 2009


On Sep 8, 10:47 pm, The Music Guy <music... at alphaios.net> wrote:
> I should also mention--and I should have realized this much
> sooner--that each of the BaseN classes are themselves each going to
> have at least one common base which will define method_x, so each
> BaseN will be calling that if it defines its own method_x. Again,
> sorry I didn't mention that sooner. For some reason it didn't occur to
> me that it would be important. I feel dumb now... :P
>
> Here is the updated current example:
>
> class CommonBase(object):
>     def method_x(self, a, b c):
>         ... no call to superclass' method_x is needed here ...
>
> class MyMixin(object):
>    def method_x(self, a, b, c):
>        get_other_base(self).method_x(self, a, b, c)
>        ...

What is get_other_base?  Just use a regular super call here,
get_other_base and hacks like that are what gets you into trouble.

You seem to be overthinking this.  You don't need to.  Just use super
() in MyMixin, and in all the other classes, consistently, and mind
the order of the bases.

And if I were you I wouldn't keep making updates to a "current
example" because first you do questionable things define a
get_other_base method, then you try to apply my advice without
reverting to the original form you posted.  Well of course you're
going to have issues if you do that.  Instead, start from scratch, and
try to get a small example working, using your orginial post and my
original suggestion.  Once that works then try to apply it to your
working example.


Carl Banks



More information about the Python-list mailing list