[Python-Dev] Multiple inheritance

Guido van Rossum guido@digicool.com
Thu, 03 May 2001 14:50:30 -0400


> Pardon if this is brief and suggestive only, I am on deadlines.

No problem.  We appreciate it!

> Super is a mistaken concept in multiple inheritance languages. Fortunately,
> Python is not brain-damaged. Its multiple inheritance model can be fixed
> easily to be fully capable.
> 
> Here is a suggestive example of implementing the Eiffel model (the only one
> that is theoretically sound) using "pretend" Python syntax (keyword
> conservationists might like "import" where I have "rename"):
> 
> 
> 1. The simple case, X inherits from Y and in defining foo and bar needs to
> use Y's version:
> 
> class X (Y rename foo as _sfoo,
>                   bar as _sbar
>         ):
>     def foo (self):
>         self._sfoo()
>         myfoostuff

Nice!  This is similar to Jeremy's favorite way of spelling "super":

class X(Y):
    Yfoo = Y.foo
    def foo(self):
        self.Yfoo()
        myfoostuff

> Suppose D inherits from B and C, which both inherit from A.
> A has a method a1 that is redefined in B but not in C.
> D wishes to use both A's version as inherited via C and B's version.
> 
> class D (B rename a1 as ba1, C rename a1 as ca1):
> 
>      can now use self.ca1, self.a1
> 
> Renaming is also useful where you inherit from a utility class and the lingo
> is different in the class where you want to use it. E.g. class Window (Tree
> rename children as subWindows)
> 
> Reference: Meyer, B. "Object-Oriented Software Construction", 2nd Edition.

Yes.

--Guido van Rossum (home page: http://www.python.org/~guido/)