It involves bytecode hacking for now, as well as a metaclass. The code is attached. It's based partially off my 'self.super' recipe, but doesn't need to use sys._getframe().
Recipe: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/286195Basically, the metaclass modifies the bytecode to include some setup code to any function that uses 'super'. The setup code generates the correct 'super' object, and stores it as a local variable. All uses of LOAD_GLOBAL(super) are changed to LOAD_FAST(super).
The one thing I would like to add is something I've got in my 'self.super' recipe - I've got my own 'super' object that is callable. Calling it invokes the super method of the current method i.e. if you've got the following code:
class A(autosuper): def f(self): pass class B(A): def f(self): super() it would be functionally identical to the following: class B(A): def f(self): super.f()This could be easily implemented by having the 'super' constructor take a 'name' parameter (which would be passed the name of current method in the setup code). Then when super() is called, it would perform the name lookup.
Tim Delaney
autosuper.py
Description: Binary data
_______________________________________________ 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