Builtn super() function. How to use it with multiple inheritance? And why should I use it at all?

Raymond Hettinger python at rcn.com
Mon Jul 26 20:46:11 EDT 2010


[Ethan Furman]
> Speaking of new-style classes only, don't they all end in object?  And
> if the MRO is only known at run-time, how is one to know at code-time
> whether your (new-style) class is at the end of the line?

That is a bit of a PITA.  One way of handling it is to design your
diamond so that only one class inherits from object and that class
doesn't use super().   Or you can wrap the super call in a try/except
AttributeError.

Cooperative multiple inheritance isn't pretty -- which is just another
good reason to use composition rather that inheritance.


Raymond




More information about the Python-list mailing list