<br><br><div><span class="gmail_quote">On 12/6/06, <b class="gmail_sendername">Josiah Carlson</b> <<a href="mailto:jcarlson@uci.edu">jcarlson@uci.edu</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;">
<br>"Thomas Wouters" <<a href="mailto:thomas@python.org">thomas@python.org</a>> wrote:<br>> On 12/6/06, Jan Grant <<a href="mailto:jan.grant@bristol.ac.uk">jan.grant@bristol.ac.uk</a>> wrote:<br>> > 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...<br>><br>><br>> You forget that that's actually what super() is for. It does the right thing<br>> in the case of MI (and every other case, in fact :-)<br><br>Except for this one:
<br><br>>>> class foo(object):<br>... pass<br>...<br>>>> class bar(foo):<br>... def method(self):<br>... super(bar, self).method()<br>...<br>>>> bar().method()<br>Traceback (most recent call last):
<br> File "<stdin>", line 1, in ?<br> File "<stdin>", line 3, in method<br>AttributeError: 'super' object has no attribute 'method'<br>>>></blockquote><div><br>I'm not sure what makes you say that. There is no superclass method 'method', so 'AttributeError' seems like the Right Thing to me.
<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;">Because of this kind of thing, I do my best to never produce code that<br>has a diamond inheritance structure (except for object), and always use
<br>things like foo.method(self).</blockquote><div><br>Which would have given you the same AttributeError.<br></div><div><br>If you want co-operative MI classes, you need to do more than just use super(): you need a baseclass that provides the 'interface', if you will, that you wish to co-operate in. For many of the standard __hooks__, object does this sensibly. For other methods, not so much. I personally think that this is correct behaviour; I wouldn't want 'return super(ThisClass, self).__gettiem__(item)' to decide to return, say, None for no apparent reason (if the typo was apparent, I wouldn't have made it :). AttributeError is the right thing.
<br></div></div><br>Avoiding MI is certainly a good option, provided you're able to enforce that policy somehow.<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!