I mucked around with this, and here is my version:

     class _super(property):
         def __init__(self):
             property.__init__(self, self.get_super, None, None)

         def get_super(self, klass):
             def dong(obj):
                 class wrapper:
                     def __getattr__(self, fn):
                         save = obj.__class__
                         obj.__class__ = klass.__mro__[1]
                         f = getattr(obj, fn)
                         obj.__class__ = save
                         return f

                 return wrapper()

             return dong

     class _superable(type):
         __super__ = _super()

     class W(object):
         __metaclass__ = _superable

         def f(self):
             print "W"

     class X(W):
         def f(self):
             print "X"
             X.__super__(self).f()

     class Y(W):
         def f(self):
             print "Y"
             Y.__super__(self).f()

     class Z(X, Y):
         def f(self):
             print "Z"
             Z.__super__(self).f()

I would rather the end result look more like this:

     class Z(X, Y):
         def f(self):
             print "Z"
             Z.__super__.f(self)

But I haven't figured out how to do that yet, and the self.__super__.f() 
pattern that Steven Bethard posted trumps it anyway!


Joel

_______________________________________________
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

Reply via email to