[Python-Dev] Improved super/autosuper (original) (raw)

Delaney, Timothy C (Timothy) tdelaney at avaya.com
Tue Jul 6 06:49:12 CEST 2004


guido at python.org wrote:

class A (autosuper):

def init (self, a, b): print 'A.init' print a, b self.super(a, b) def test (self, a, b): print 'A.test' print a, b self.super(a, b) class B (A): def init (self): print 'B.init' self.super(1, 2) self.super.test(3, 4) One more thing... What is the point of self.super.test(...)? When is that not the same as self.test(...)? What's the use case?

import autosuper

class A (autosuper.autosuper):

def __init__ (self, a, b):
    print 'A.__init__'
    print a, b
    self.super(a, b)

def test (self, a, b):
    print 'A.test'
    print a, b
    self.super(a, b)

class B (A):

def __init__ (self):
    print 'B.__init__'
    self.super(1, 2)
    super(B, self).test(3, 4)

def test (self, a, b):
    print 'B.test'
    self.super(a, b)

B()

---------- Run ---------- B.init A.init 1 2 A.test 3 4

Output completed (0 sec consumed) - Normal Termination

As you can see, B.test did not get called. By doing self.super.test, I'm guaranteeing that I'll only see attributes higher in the MRO.

Whether it's a useful thing or not, it's something you can do now with super.

Tim Delaney



More information about the Python-Dev mailing list