invoking a method from two superclasses

Mitchell L Model MLMLists at Comcast.net
Tue Jun 30 20:34:02 EDT 2009


Allow me to add to my previous question that certainly the superclass
methods can be called explicitly without resorting to super(), e.g.:

    class C(A, B):
        def __init__(self):
            A.__init__(self)
            B.__init__(self)

My question is really whether there is any way of getting around the
explicit class names by using super() and if not, shouldn't the documentation
of super point out that if more than one class on the mro defines a method
only the first will get called?  What's strange is that it specifically mentions
diamond patterns, which is an important case to get right, but it doesn't show
how.

I suspect we should have a Multiple Inheritance HOWTO, though details and
recommendations would be controversial. I've accumulated lots of abstract
examples along the lines of my question, using multiple inheritance both to
create combination classes (the kinds that are probably best done with
composition instead of inheritance) and mixins. I like mixins, and I like abstract
classes. And yes I understand the horrors of working with a large component
library that uses mixins heavily, because I've experienced many of them, going
all the way back to Lisp-Machine Lisp's window system with very many combo
classes such as FancyFontScrollingTitledMinimizableWindow, or whatever.
Also, I understand that properties might be better instead of multiple inheritance 
for some situations. What I'm trying to do is puzzle out what the reasonable uses
of multiple inheritance are in Python 3 and how classes and methods that follow
them should be written.



More information about the Python-list mailing list