Search code examples
pythondbuspygobjectdbus-python

PyGObject, dbus python and metaclasses


I want to subclass two python classes: one from PyGObject and one from python3-dbus:

import gi
from gi.repository import GObject
import dbus.service

class Test(GObject.Object, dbus.service.Object):
    pass

However I'm receiving following error:

$ python3 test.py
Traceback (most recent call last):
    File ".../test.py", line 5, in <module>
       class Test(GObject.Object, dbus.service.Object):
TypeError: metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases

I've already find out that it is because GObject.Object and dbus.service.Object have different metaclasses, and I need to do subclass them too:

class M_Test(gi.types.GObjectMeta, dbus.service.InterfaceType):
    pass

class Test(GObject.Object, dbus.service.Object):
    __metaclass__=M_Test
    pass

However it doesn't help, I continue to receive the same error. Maybe gi.types.GObjectMeta and dbus.service.InterfaceType is not correct metaclasses for GObject.Object and dbus.service.Object. Does anybody know how to do merge metaclasses of GObject.Object and dbus.service.Object?


Solution

  • Python3 changed syntax of specifying metaclasses. PEP-3115

    It's class Test(GObject.Object, dbus.service.Object, metaclass=M_Test): now.