我想继承两个 python 类:一个来自 PyGObject,一个来自 python3-dbus:
import gi
from gi.repository import GObject
import dbus.service
class Test(GObject.Object, dbus.service.Object):
pass
但是我收到以下错误:
$ 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
我已经发现这是因为GObject.Object
并且dbus.service.Object
有不同的元类,我也需要对它们进行子类化:
class M_Test(gi.types.GObjectMeta, dbus.service.InterfaceType):
pass
class Test(GObject.Object, dbus.service.Object):
__metaclass__=M_Test
pass
但是它没有帮助,我继续收到同样的错误。也许gi.types.GObjectMeta
和dbus.service.InterfaceType
不是正确的元类GObject.Object
和dbus.service.Object
。有人知道如何合并GObject.Object
和的元类dbus.service.Object
吗?