No TypeError raised for missing abc.abstractmethod when deriving a PySide6 widget

45 views Asked by At

I have an object that inherits both from a QWidget and an abc.ABC interface. See MyWindow in my example below.

import abc
from PySide6 import QtCore, QtWidgets
#from PyQt6 import QtCore, QtWidgets    # It works as expected in PyQt6
#from PyQt5 import QtCore, QtWidgets    # Idem for PyQt5

class Interface(abc.ABC):

    @abc.abstractmethod
    def myMethod(self, a):
        pass

class NormalClass(Interface):
    def myMethod(self, a):
        "When you delete this method, you get an error as expected."
        print("my method normally")

class QObjectAbcMeta(type(QtCore.QObject), type(abc.ABC)):
    pass

class MyWindow(QtWidgets.QWidget, Interface, metaclass=QObjectAbcMeta):
    # Even though myMethod is missing, you don't get an error with PySide6
    pass

def main():
    normal = NormalClass()

    app = QtWidgets.QApplication([])
    win = MyWindow()
    win.show()
    app.exec()

if __name__ == "__main__":
    main()

I would expect that Python raises a TypeError here because the MyWindow class is missing a definition for the myMethod abstract method. However, it just runs without any error.

When I use PyQt6 I get a TypeError as expected. Also when I don't inherit from QWidget (my NormalClass) it works as expected.

Does anybody know a solution?

0

There are 0 answers