[Python-ideas] [Python-Dev] python and super

Michael Foord fuzzyman at voidspace.org.uk
Sat Apr 16 19:22:44 CEST 2011


On 16/04/2011 00:38, Greg Ewing wrote:
> Michael Foord wrote:
>
>> consider the "recently" introduced problem caused by object.__init__
> > not taking arguments. This makes it impossible to use super correctly
> > in various circumstances.
> >
> > ...
> >
>> It is impossible to inherit from both C and A and have all parent
>> __init__ methods called correctly. Changing the semantics of super as
>> described would fix this problem.
>
> I don't see how, because auto-super-calling would eventually
> end up trying to call object.__init__ with arguments and fail.
>

No, not as I described. Where a method does not call up to its parent 
class then super would *not* auto call the parent class (I'm *not* 
suggesting a fully auto-call super as the original poster did), but a 
method not calling super still wouldn't halt the chain of calls. To 
achieve this a call into a method that doesn't call super (and would 
normally end the chain) instead removes itself and its unique parents 
[1] from the mro for this call.

It would make the semantics more complex, but it would solve this 
problem and the original posters problem. For this specific example, if 
no classes call up to object.__init__ then it won't be called. It would 
permit you to have methods that can participate in multiple inheritance 
whilst still blocking calls (overriding) up to their parent classes.

All the best,

Michael

[1] i.e. classes that aren't also the parent of another class still in 
the mro.

> You might think to "fix" this by making a special case of
> object.__init__ and refraining from calling it. But the same
> problem arises in a more general way whenever some class in
> the mix has a method with the right name but the wrong
> signature, which is likely to happen if you try to mix
> classes that weren't designed to be mixed together.
>


-- 
http://www.voidspace.org.uk/

May you do good and not evil
May you find forgiveness for yourself and forgive others
May you share freely, never taking more than you give.
-- the sqlite blessing http://www.sqlite.org/different.html




More information about the Python-ideas mailing list