Inheritance and Design Question

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Thu May 28 06:06:39 CEST 2009


On Wed, 27 May 2009 17:21:23 -0400, Terry Reedy wrote:

> super() was designed for multiple inheritance.

Surely you mean that super() was designed for *inheritance*, multiple or 
singular? Working with single inheritance is part of the design, not an 
accident of implementation.


> The only reason I know
> to use it with single inheritance it to save a
> global-search-and-replace_with_confirmation if you change the name of
> the parent or change parents.

How about these reasons?

(1) If you're subclassing something you didn't write, you might not know 
whether it uses multiple or single inheritance.

(2) Even if you do know, you shouldn't care what the implementation of 
the parent is. Using super() allows you to be agnostic about the 
implementation, while calling Parent.method() directly ties you to a 
specific implementation.

(3) Your callers may want to inherit from your class, and if you fail to 
use super, you are condemning them to potentially buggy code if they use 
multiple inheritance.

(4) Using super() is no harder than avoiding super(). It takes a few 
extra characters to type, at worst:

super(MyClass, self).method(args)
Parent.method(self, args)


-- 
Steven



More information about the Python-list mailing list