By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,923 Members | 1,279 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,923 IT Pros & Developers. It's quick & easy.

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

P: n/a
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?
Oct 31 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Alex Hunsley wrote:
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>
--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'o****@xiludom.gro'.split('@')])"
Oct 31 '05 #2

P: n/a
Alex Hunsley <la**@tardis.ed.ac.molar.uk> wrote:
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
Oct 31 '05 #3

P: n/a
Alex Hunsley wrote:
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/

--
Giovanni Bajo
Nov 1 '05 #4

P: n/a
Giovanni Bajo wrote:
Alex Hunsley wrote:

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/

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.
Nov 2 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.