[Python-Dev] Re: super() harmful?

Delaney, Timothy C (Timothy) tdelaney at avaya.com
Thu Jan 6 23:45:55 CET 2005


Guido van Rossum wrote:

>> and the cumbersome way in which you have to invoke super.
> 
> Given Python's dynamic nature I couldn't think of a way to make it
> less cumbersome. I see you tried (see below) and couldn't either. At
> this point I tend to say "put up or shut up."

Well, there's my autosuper recipe you've seen before:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/286195

which does basically what Philip descibes ...

>>> import autosuper
>>>
>>> class A (autosuper.autosuper):
...     def test (self, a):
...         print 'A.test: %s' % (a,)
...
>>> class B (A):
...     def test (self, a):
...         print 'B.test: %s' % (a,)
...         self.super(a + 1)
...
>>> class C (A):
...     def test (self, a):
...         print 'C.test: %s' % (a,)
...         self.super.test(a + 1)
...
>>> class D (B, C):
...     def test (self, a):
...         print 'D.test: %s' % (a,)
...         self.super(a + 1)
...
>>> D().test(1)
D.test: 1
B.test: 2
C.test: 3
A.test: 4

It uses sys._getframe() of course ...

Tim Delaney


More information about the Python-Dev mailing list