Multiple inheritance - How to call method_x in InheritedBaseB from method_x in InheritedBaseA?
Carl Banks
pavlovevidence at gmail.com
Wed Sep 9 19:58:27 EDT 2009
On Sep 9, 4:37 pm, The Music Guy <music... at alphaios.net> wrote:
> On Wed, Sep 9, 2009 at 1:21 PM, Carl Banks<pavlovevide... at gmail.com> wrote:
> > On Sep 8, 10:47 pm, The Music Guy <music... at alphaios.net> wrote:
> > 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.
>
> get_other_base() is supposed to return the other superclass (base)
> that is being used in conjunction with the current superclass. So if
> FooX inherits from MyMixin and BaseB, and get_other_base(self) is
> called from a method defined in MyMixin, BaseB is returned. In any
> case, that function is merely psuedocode, not an actual part of the
> implementation.
Ah, but see unless you tell us that, we will not know and will give
you inappropriate advice. Moral of the story: post the code that you
actually ran. And if you take anyone's advice, apply it to the actual
code they were advising you on.
> Its purpose in my example was merely to show the
> effect I was trying to acheive. I used it because I'm having trouble
> understanding exactly how the super() function works; it always seems
> to do something I didn't expect, or not do something that I did
> expect. (I say this after having read the online documentation, btw.)
super() is unfortunately misnamed after the analogous feature of Java;
the analogy breaks down under multiple inheritance. Think of super as
more like "call next method", where the next method could be from a
base class or a sister class. However it always works left to right
in the list of bases, which is why it was important for MyMixin to be
listed first.
> Anyway, Ryles' last suggestion helped a lot. Thanks, Ryles. (And Carl
> and Scott, too, of course.) Here's the code I'm going with:
I'm glad it worked out.
Carl Banks
More information about the Python-list
mailing list