I am building an app in PySide6 that will involve dynamic loading of plugins. To facilitate this, I am using ABCMeta
to define a custom class for the plugin interface, and I would like this custom class to inherit from ABC
and from QObject
so that I can abstract as much of the behavior as possible, including things like standard signals and slots that will be common to all subclasses.
I have set up a MWE that shows the chain of logic that enabled me to get this setup working, but the chain of inheritance goes deeper than I thought it would. Is it possible to shorten this while still having the desired inheritance? In the end, my goal is to have the MetaTab
class as an abstract base class that inherits from ABC so that I can define @abstractmethods
inside it, and then subclass that for individual plugins. Do I really need both QABCMeta
and QObjectMeta
to make this work, or is there a way to clean it up that eliminates one of the links in this inheritance chain?
from abc import ABC, ABCMeta, abstractmethod
from PySide6.QtCore import QObject
class QABCMeta(ABCMeta, type(QObject)):
pass
class QObjectMeta(ABC, metaclass=QABCMeta):
pass
class MetaTab(QObject, QObjectMeta):
def __init__(self, x):
print('initialized')
self.x = x
@abstractmethod
def print_value(self):
pass
class Tab(MetaTab):
def __init__(self, x):
super().__init__(x)
def print_value(self):
print(self.x)
def main():
obj = Tab(5)
for b in obj.__class__.__bases__:
print("Base class name:", b.__name__)
print("Class name:", obj.__class__.__name__)
obj.print_value()
if __name__=='__main__':
main()