[Python-ideas] descriptors outside of classes

Greg Ewing greg.ewing at canterbury.ac.nz
Thu Mar 31 04:18:26 CEST 2011


Guido van Rossum wrote:
> We need a python-hacks list. :)

Very tangentially related, here's my latest piece of
dubious hackery, written the other day to work around
the fact that multiple inheritance seems to be broken
in conjunction with gobject introspection. It plays
fast and loose with the method resolution order, but
it got me out of a tight corner.

def mix_in(*src_classes):
     #  Workaround for do_xxx method overrides not working properly
     #  with multiple inheritance.
     #
     #  Usage:
     #
     #    class MyClass(Gtk.SomeBaseClass):
     #      mix_in(Class1, Class2, ...)
     #
     import sys
     frame = sys._getframe(1)
     dst_dict = frame.f_locals
     for src_class in src_classes:
         for name, value in src_class.__dict__.iteritems():
             if name not in dst_dict:
                 dst_dict[name] = value

-- 
Greg




More information about the Python-ideas mailing list