<br><div><span class="gmail_quote">On 4/19/06, <b class="gmail_sendername">Guido van Rossum</b> <<a href="mailto:guido@python.org">guido@python.org</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 4/19/06, Phillip J. Eby <<a href="mailto:pje@telecommunity.com">pje@telecommunity.com</a>> wrote:<br>> Here's how you solve the "how does super() get the current class" problem,<br>> using existing compiler and VM constructs, and without relying on class
<br>> names, or on functions not being decorated, or anything like that. And<br>> it's so simple you'll slap your forehead for not thinking of it first. :)<br><br>Actually, I *did* think of it first. :-)<br><br>
<a href="http://mail.python.org/pipermail/python-3000/2006-April/000947.html">http://mail.python.org/pipermail/python-3000/2006-April/000947.html</a></blockquote><div><br></div>And yet before that:<br><a href="http://mail.python.org/pipermail/python-3000/2006-April/000922.html">
http://mail.python.org/pipermail/python-3000/2006-April/000922.html</a> <br><div><br></div>Needless to say, I'm in favour, if it can be swung ;-)<br><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Oh, I believe super() also supports static and/or class methods. I'm<br>not sure how to handle this but I'm sure you can think of something.</blockquote><div><br>It should just use the descriptor magic to retrieve the right method object from the stored 'current class', passing the class and instance (if any) as usual. That does mean, though, that super (however you want to spell it) needs to be informed what the instance or class is. The current super() call is explicitly passed 'self' (or 'cls' for classmethods), but it has no way of operating in staticmethods unless they are really classmethods in disguise (like __new__, a staticmethod that gets the class as first argument.) since, with neither 'self' nor 'cls', there is no way for super to figure out the right MRO.
<br></div><br></div>So, super would have to be used like so:<br><br> def meth(self, arg, kwarg=kwval):<br> return super.meth(self, arg, kwarg=kwval)<br> @classmethod<br> def cmeth(cls, arg, kwarg=kwval):<br> return
super.cmeth(cls, arg, kwarg=kwval)<br clear="all"> @staticmethod<br> def smeth(cls, arg, kwarg=kwval):<br> # cls is not necessarily the right class, but it's the best guess<br> return super.smeth(cls, arg, kwarg=kwval)
<br><br>Which looks quite a bit like the old BaseClass.meth(self, ...) calls. I think it's a pity we can't make it look more like normal methodcalls, maybe by passing the class or instance explicitly: super(self).meth(arg, kwargv=kwval) (and super(cls) for classmethods.) Unfortunately, that is entirely and silently and somewhat surprisingly incompatible with Python
2.x, where super(cls) creates an unbound super proxy.<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!