<br><br><div><span class="gmail_quote">On 12/6/06, <b class="gmail_sendername">Jan Grant</b> <<a href="mailto:jan.grant@bristol.ac.uk">jan.grant@bristol.ac.uk</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
On Mon, 4 Dec 2006, Ben Wing wrote:<br><br>> as a result, i imagine there's a strong urge to just hardcode the name<br>> of the parent<br> ^^^^^^^^^^<br><br>> -- super.meth(args) calls the superclass method `meth'
<br> ^^^^^^^^^^^^^^<br><br>Python supports multiple inheritance, unlike Java; the design mantra is<br>"explicit is better than implicit" and "ambiguity should be an error".<br>
Two! The two design mantras are...</blockquote><div><br>You forget that that's actually what super() is for. It does the right thing in the case of MI (and every other case, in fact :-)<br></div><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
> -- as an alternative or in addition, super(args) would work like<br>> super.meth(args) if we're currently inside of `meth' in a subclass. i<br>> suspect that 90% of the time or more, `super' is used to chain to the
<br>> superclass version of an overridden method, and this optimizes for the<br>> common case.<br><br>Commonly you know what the method is called at the point where you're<br>typing "super" :-)</blockquote>
<div><br>The point is not that it's difficult to come up with the arguments to super(ThisClass, self).methodname(args), but that it's tedious and sometimes unobvious and error-prone. super should definately be enhanced so 'super(args)' and '
super.meth' 'do the right thing' too, but as Nick said, it's not that easy :) It would help if someone started on an implementation though. (It's on my TODO list, but that list is rather swamped with "new job" things.)
<br></div></div><br>(For an example of 'tricky things', when you do:<br> class X(Y):<br> def meth(self, x, y):<br> return super(x) + y<br> moremeth = meth<br> -- should X().moremeth(1, 2) call Y.meth() or
Y.moremeth()? It could probably be implemented either way, with enough magic in the runtime.)<br><br>-- <br>Thomas Wouters <<a href="mailto:thomas@python.org">thomas@python.org</a>><br><br>Hi! I'm a .signature virus! copy me into your .signature file to help me spread!