'super' to only be used for diamond inheritance problems?

A

Alex Hunsley

I've seen a few discussion about the use of 'super' in Python, including
the opinion that 'super' should only be used to solve inheritance
diamond problem. (And that a constructor that wants to call the
superclass methods should just call them by name and forget about super.)
What is people's opinion on this? Does it make any sense?
 
B

bruno at modulix

Alex said:
I've seen a few discussion about the use of 'super' in Python, including
the opinion that 'super' should only be used to solve inheritance
diamond problem. (And that a constructor that wants to call the
superclass methods should just call them by name and forget about super.)
What is people's opinion on this? Does it make any sense?

<imho>
Since you'll never know how your class will be used, better to stick
with super... super(MyClass, self).dothis() is no more difficult to use
than MySuperClass.dothis(self), and does not require much more typing,
so I don't see any reason not to use it.
</imho>
 
A

Alex Martelli

Alex Hunsley said:
I've seen a few discussion about the use of 'super' in Python, including
the opinion that 'super' should only be used to solve inheritance
diamond problem. (And that a constructor that wants to call the
superclass methods should just call them by name and forget about super.)
What is people's opinion on this? Does it make any sense?

No, it makes no sense whatsoever. Any situation where multiple
inheritance is possible, diamonds or no diamonds, can benefit from
cooperative superclass calling where needed (e.g., __init__). Consider:

class A(B, C): ...

should A know or care at all whether B and C share common bases? Of
course not -- why should A have to be burdened with that knowledge?! To
ensure __init__ is called on each base once and only once,
systematically using super(A, self) is the best and simplest way.

Another way to put it: there's ALWAYS "meshes" (diamonds or more
complicated forms), whenever multiple inheritance occurs, because (in
the newstyle object model, and the other one only exists for legacy
reasons and shouldn't be used in new code) object is always among the
ancestors of EVERY class. So, again: use super.


Alex
 
G

Giovanni Bajo

Alex said:
I've seen a few discussion about the use of 'super' in Python,
including the opinion that 'super' should only be used to solve
inheritance diamond problem. (And that a constructor that wants to
call the superclass methods should just call them by name and forget
about super.) What is people's opinion on this? Does it make any
sense?


I personally consider super a half-failure in Python. Some of my reasons are
cited here:
http://fuhm.org/super-harmful/
 
C

Colin J. Williams

Giovanni said:
Alex Hunsley wrote:





I personally consider super a half-failure in Python. Some of my reasons are
cited here:
http://fuhm.org/super-harmful/
It would help to have some clearer guidelines on class (type) usage. I
like James Knight's (fuhm) suggestion with respect to consistent signatures.

Colin W.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top