[pygtk] gobject & metaclasses

Alessandro Dentella sandro at e-den.it
Mon Oct 27 18:20:54 WST 2008


> On Sun, Oct 26, 2008 at 4:30 AM, Alessandro Dentella <sandro a e-den.it> wrote:
> > TypeError: Error when calling the metaclass bases
> >    metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases
> >
> >
> > What does this mean and what should I do instead?
> 
> This is actually a generic python question, but to recognize it, you
> have to know that GObject has its own metaclass. The similar case in

I was undecided if addressing to python list or pygtk, in fact.

> (shortened) pure python is:
> 
> class meta1(type): pass
> class meta2(type): pass
> class base(meta1): __metaclass__ = meta1
> class derv(base): __metaclass__ = meta2
> 
> To fix it up, you have to mix the metaclasses (and use real
> metaclasses, of course):
> 
> class mmeta(meta1, meta2): pass
> class derv(base): __metaclass__ = mmeta

I had this idea and I tryed what follows that in my idea is what you
suggest, changes the error...

   import gobject

   class Dummy(type, gobject.GObject):
       def __new__(cls, name, bases, attrs):
	   return type.__new__(cls, name, bases, attrs)


   class A(object):
       __metaclass__ = Dummy


And the error becomes:

  TypeError: Error when calling the metaclass bases
      multiple bases have instance lay-out conflict


A quick search in google seem to warn that this means that type and GObject
are not built to work toghether... is this True?


sandro
*:-)



More information about the pygtk mailing list