<br><br><div><span class="gmail_quote">On 12/6/06, <b class="gmail_sendername">Josiah Carlson</b> &lt;<a href="mailto:jcarlson@uci.edu">jcarlson@uci.edu</a>&gt; 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>&quot;Thomas Wouters&quot; &lt;<a href="mailto:thomas@python.org">thomas@python.org</a>&gt; wrote:<br>&gt; On 12/6/06, Jan Grant &lt;<a href="mailto:jan.grant@bristol.ac.uk">jan.grant@bristol.ac.uk</a>&gt; wrote:<br>&gt; &gt; On Mon, 4 Dec 2006, Ben Wing wrote:
<br>&gt; &gt;<br>&gt; &gt; &gt; as a result, i imagine there's a strong urge to just hardcode the name<br>&gt; &gt; &gt; of the parent<br>&gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;^^^^^^^^^^<br>&gt; &gt;<br>&gt; &gt; &gt; -- super.meth(args) calls the superclass method `meth'
<br>&gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ^^^^^^^^^^^^^^<br>&gt; &gt;<br>&gt; &gt; Python supports multiple inheritance, unlike Java; the design mantra is<br>&gt; &gt; &quot;explicit is better than implicit&quot; and &quot;ambiguity should be an error&quot;.
<br>&gt; &gt; Two! The two design mantras are...<br>&gt;<br>&gt;<br>&gt; You forget that that's actually what super() is for. It does the right thing<br>&gt; in the case of MI (and every other case, in fact :-)<br><br>Except for this one:
<br><br>&gt;&gt;&gt; class foo(object):<br>...&nbsp;&nbsp;&nbsp;&nbsp; pass<br>...<br>&gt;&gt;&gt; class bar(foo):<br>...&nbsp;&nbsp;&nbsp;&nbsp; def method(self):<br>...&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; super(bar, self).method()<br>...<br>&gt;&gt;&gt; bar().method()<br>Traceback (most recent call last):
<br>&nbsp;&nbsp;File &quot;&lt;stdin&gt;&quot;, line 1, in ?<br>&nbsp;&nbsp;File &quot;&lt;stdin&gt;&quot;, line 3, in method<br>AttributeError: 'super' object has no attribute 'method'<br>&gt;&gt;&gt;</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 &lt;<a href="mailto:thomas@python.org">thomas@python.org</a>&gt;<br><br>Hi! I'm a .signature virus! copy me into your .signature file to help me spread!