Needed: Real-world examples for Python's Cooperative Multiple Inheritance

Raymond Hettinger raymond.activestate at gmail.com
Thu Nov 25 20:36:43 EST 2010


On Nov 25, 3:38 pm, John Nagle <na... at animats.com> wrote:
>     Multiple inheritance in Python is basically what fell out of
> CPython's internals, not a design.  

Sorry to disagree.  That is historically inaccurate.
Guido designed super() on purpose.  He took his cues from
"Putting Metaclasses to Work" by Ira Forman and Scott Danforth.

The method resolution order was based on yet another paper
which showed the defects in the two earlier designs for
multiple inheritance.

It may not be great, but it sure wasn't an accident.


>     Best practice for this is "don't do it."  Some name clashes ought
> to simply be detected as errors, rather than being given such
> complex semantics.

That may well be true.  If a coder has enough control over the classes
to be make sure they use super() in a way that supports cooperative
multiple inheritance, then they have enough control to just
rename the methods to prevent name diamond shaped name clashes.

OTOH, sometimes you don't have control over the names if they
are magic methods or standard names like close(), save(), flush(),
__init__(), etc.

Raymond



More information about the Python-list mailing list