[Python-3000] Fixing super anyone?

Guido van Rossum guido at python.org
Thu Apr 19 00:15:49 CEST 2007


On 4/18/07, Jim Jewett <jimjjewett at gmail.com> wrote:
> On 4/18/07, Guido van Rossum <guido at python.org> wrote:
> > Is anyone available to write up a PEP on how to turn super into a
> > keyword? Inside regular and class methods, super.foo(args) should be
> > equivalent to super(ThisClass, self).foo(args). I think there are ways
> > to make the old syntax work too, but maybe that's only necessary for
> > 2.6.
>
> Does this mean it should find the super of the current class (which
> isn't yet defined when the method is being defined)?
>
> That would be a slight change (though probably an improvement) against
> today's lookup-by-name.

Right. It should definitely use the current class and not the name of
the current class. I hope you'll be able to find a way to implement
this! Perhaps the class could be gotten from a hidden cell reference,
where the cell is filled in by the metaclass whe the class is created.
(The cell can't represent the result of the super call, because that
also incorporates the current value of 'self', for which you can use
the first argument.)

So the syntax "super" could be translated into "super(__thisclass__,
self)" where __thisclass__ is the cell reference, self refers to the
(current or original?) value of the first argument, and super is
exactly the same as the 2.x super function. (Though it could be
referenced via an opcode.)

> If that change is OK, and no one else volunteers, I'll try to take a
> go at it this weekend.

Thanks!

-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-3000 mailing list