On 12/6/06, Josiah Carlson <[EMAIL PROTECTED]> wrote:
"Thomas Wouters" <[EMAIL PROTECTED]> wrote: > On 12/6/06, Jan Grant <[EMAIL PROTECTED]> wrote: > > On Mon, 4 Dec 2006, Ben Wing wrote: > > > > > as a result, i imagine there's a strong urge to just hardcode the name > > > of the parent > > ^^^^^^^^^^ > > > > > -- super.meth(args) calls the superclass method `meth' > > ^^^^^^^^^^^^^^ > > > > Python supports multiple inheritance, unlike Java; the design mantra is > > "explicit is better than implicit" and "ambiguity should be an error". > > Two! The two design mantras are... > > > 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 :-) Except for this one: >>> class foo(object): ... pass ... >>> class bar(foo): ... def method(self): ... super(bar, self).method() ... >>> bar().method() Traceback (most recent call last): File "<stdin>", line 1, in ? File "<stdin>", line 3, in method AttributeError: 'super' object has no attribute 'method' >>>
I'm not sure what makes you say that. There is no superclass method 'method', so 'AttributeError' seems like the Right Thing to me. Because of this kind of thing, I do my best to never produce code that
has a diamond inheritance structure (except for object), and always use things like foo.method(self).
Which would have given you the same AttributeError. 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. Avoiding MI is certainly a good option, provided you're able to enforce that policy somehow. -- Thomas Wouters <[EMAIL PROTECTED]> Hi! I'm a .signature virus! copy me into your .signature file to help me spread!
_______________________________________________ Python-3000 mailing list Python-3000@python.org http://mail.python.org/mailman/listinfo/python-3000 Unsubscribe: http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com