[Python-3000] auto-super()

Delaney, Timothy (Tim) tdelaney at avaya.com
Wed Apr 19 01:03:56 CEST 2006


Guido van Rossum wrote:

> Let's leave this topic behind for a while. Hacks that can be
> implemented only using sys._getframe() are not generally suitable for
> including in the standard library or making part of the language spec.

Yep - there's no way I'd consider such a hack for the python
distribution. I was just interested that the conversation appeared to be
converging on the recipe (more proof-of-concept) I created quite some
time ago :)

I'd really like to work out a way to do it without sys._getframe()
hacks. Apart from anything else, it really needs to perform at similar
speed to super(cls, self).

Perhaps when a code object is constructed it could include a reference
to the class where it was constructed (if any). Then the class to use in
`super` would be obtained directly. I originally wanted to use im_class
rather than walk the MRO, but im_class didn't give the correct result,
and in any case I'd still need sys._getframe().

This approach would of course not work properly if the same method was
then added to another class (a flaw shared by my recipe IIRC). One way
to deal with that would be to check that the class was actually in the
MRO of the current instance, and throw a TypeError if it's not.

Tim Delaney


More information about the Python-3000 mailing list