[Python-Dev] Improved super/autosuper

Delaney, Timothy C (Timothy) tdelaney at avaya.com
Tue Jul 6 02:25:18 CEST 2004


The current `super` implementation was always (as I understood it) meant
to be an interim solution until a better syntax could be determined.
I've submitted a recipe to the Cookbook for an improved super/autosuper
which allows using syntax like:

    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)

    B()

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/286195

It's currently got some fairly serious inefficiencies in it, but it
shows that it is viable to produce a simpler `super` that doesn't
require hardcoding the class. It's also backwards-compatible.

Would there be any interest in doing further work on this with the aim
of getting it into the core?

BTW, I've made a couple of design choices which I'm not sure about.
Specifically, I've made `self.super` *not* throw an AttributeError when
no base class has the attribute - this simplifies dealing with mixin
classes (since you can just blindly put the self.super call in). I've
included a second property `super_raise` for when you want the
exception. Most of my usage works better without the exception (since
everything resolves back to object, and it doesn't have many methods
...). But I'd like other people's opinion on which is preferable.

Cheers.

Tim Delaney 


More information about the Python-Dev mailing list