On 4/19/06, Guido van Rossum <[EMAIL PROTECTED]> wrote:
On 4/19/06, Phillip J. Eby <[EMAIL PROTECTED]> wrote:
> Here's how you solve the "how does super() get the current class" problem,
> using existing compiler and VM constructs, and without relying on class
> names, or on functions not being decorated, or anything like that.  And
> it's so simple you'll slap your forehead for not thinking of it first.  :)

Actually, I *did* think of it first. :-)

     http://mail.python.org/pipermail/python-3000/2006-April/000947.html

And yet before that:
http://mail.python.org/pipermail/python-3000/2006-April/000922.html

Needless to say, I'm in favour, if it can be swung ;-)

Oh, I believe super() also supports static and/or class methods. I'm
not sure how to handle this but I'm sure you can think of something.

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.

So, super would have to be used like so:

 def meth(self, arg, kwarg=kwval):
     return super.meth(self, arg, kwarg=kwval)
 @classmethod
 def cmeth(cls, arg, kwarg=kwval):
     return super.cmeth(cls, arg, kwarg=kwval)
 @staticmethod
 def smeth(cls, arg, kwarg=kwval):
     # cls is not necessarily the right class, but it's the best guess
     return super.smeth(cls, arg, kwarg=kwval)

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.

--
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

Reply via email to