Override method name and original method access

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Wed Nov 14 00:14:01 EST 2007


En Tue, 13 Nov 2007 17:14:07 -0300, Chris Mellon <arkanes at gmail.com>  
escribió:

> On Nov 13, 2007 3:00 AM, Gabriel Genellina <gagsl-py2 at yahoo.com.ar>  
> wrote:

>> You may prefer keeping your old-style classes and avoid using
>> super, if you don't have multiple inheritance. Just call explicitely the
>> base class.
>
> It's a lot harder to change your object hierarchy to use super() after
> the fact than it is to do explicit superclass calling in some class
> that you decide to use different signatures for. The use of super()
> (and new style classes) should be the default implementation, and you
> should only move away from that with an explicit reason. Telling
> people not to use super when there's no reason not to doesn't help
> anything.

You shouldn't use super always, and by no means super "should be the  
default implementation". Remember that super() calls "the next method in  
the mro chain", not "the base class method". super is aimed to help solve  
a specific problem: cooperative multiple inheritance. M.I. is a nightmare  
by itself, and super is *not* a magic elixir that will cure all  
inheritance diseases. This page "Python's Super Considered Harmful" [1]  
summarizes some problems with super.

Back on the OP problem, he wanted to call One.add from Two.__init__,  
avoiding to call Two.add. This does *not* look like "cooperative multiple  
inheritance", so I don't see that super() is the right thing here.


[1] http://fuhm.org/super-harmful/

-- 
Gabriel Genellina




More information about the Python-list mailing list