<br><br><div class="gmail_quote">On Fri, May 27, 2011 at 4:37 AM, Steven D'Aprano <span dir="ltr"><<a href="mailto:steve%2Bcomp.lang.python@pearwood.info">steve+comp.lang.python@pearwood.info</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div class="im">On Fri, 27 May 2011 18:49:52 +1000, Ben Finney wrote:<br>
<br>
> Raymond Hettinger <<a href="mailto:python@rcn.com">python@rcn.com</a>> writes:<br>
><br>
>> Hope you enjoyed the post.<br>
><br>
> I certainly did.<br>
><br>
> But I'm not better enlightened on why ‘super’ is a good thing.<br>
<br>
</div>Perhaps Raymond assumed that by now everybody knows that multiple<br>
inheritance in Python that doesn't use super is buggy. super() was<br>
introduced in version 2.2 in order to overcome bugs in MI, making it<br>
about 8 years old now.<br>
<br>
(Technically, it's only MI with diamond-shaped inheritance, but that<br>
applies to *all* new-style classes. If you're writing multiple<br>
inheritance in Python 3 without using super, your code is a land-mine<br>
waiting to go off. If you're writing single inheritance, it's *still* a<br>
land-mine, just waiting for some poor caller to use it in a MI context.)<br>
<br>
But I do agree with you in that I expected to see at least some<br>
discussion of why super should be actively preferred over calling the<br>
parent class directly.<br>
<div class="im"><br></div></blockquote><div><br></div><div>Seems like he does just that for most of the first section.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im"> </div></blockquote><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div class="im">
> The<br>
> exquisite care that you describe programmers needing to maintain is IMO<br>
> just as much a deterrent as the super-is-harmful essay.<br>
<br>
</div>I don't see that Raymond describes anything needing "exquisite care".<br>
It's more common sense really: ensure that your method signature and that<br>
of your parents' match, plus good work-arounds for when they don't.<br>
Anyone using inheritance is almost certainly 98% of the way there, unless<br>
they're writing classes like this and wondering why they don't work :)<br>
<br>
class MyBrokenList(list):<br>
    def __len__(self):<br>
        n = list.__len__(self, extra=42)<br>
        return n + 1<br>
    def __getitem__(self, i):<br>
        return list.__getitem__(self) + 1<br>
    def last_item(self):<br>
        return list.last_item(self) + 1<br>
<br>
<br>
I was thrilled to learn a new trick, popping keyword arguments before<br>
calling super, and wondered why I hadn't thought of that myself. How on<br>
earth did I fail to realise that a kwarg dict was mutable and therefore<br>
you can remove keyword args, or inject new ones in?<br>
<br>
Given the plethora of articles that take a dim, if not outright negative,<br>
view of super, it is good to see one that takes a positive view. Thanks<br>
Raymond!<br>
<br></blockquote><div><br></div><div>+1</div><div><br></div><div>-eric</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<br>
<br>
--<br>
<font color="#888888">Steven<br>
</font><div><div></div><div class="h5">--<br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
</div></div></blockquote></div><br>