Improved super/autosuper

Delaney, Timothy C (Timothy) tdelaney at
Tue Jul 6 02:12:33 CEST 2004

OK - I've updated the recipe (though it's not available for general
viewing yet).

autosuper is now a mixin class. Two properties are available -
self.super and self.super_raise. Use self.super if you don't want an
AttributeError to be raised if no base class has the attribute. Use
self.super_raise if you do.

The object returned by self.super and self.super_raise is a callable
wrapper. If you call it, it will call the method on a base class with
the same name as the method that self.super was called from.
Alternately, you can access attributes/methods on the returned object.

    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)



    1 2
    3 4

Code is attached.

Tim Delaney
-------------- next part --------------
A non-text attachment was scrubbed...
Type: application/octet-stream
Size: 7424 bytes
URL: <>

More information about the Python-list mailing list