Pyside6/Shiboken and ABCMeta Bug

473 views Asked by At

This is specific to the new Pyside6 package. Pyside2 does not have this issue.

When attempting to create an abstract class combining JSON and QObject classes Shiboken throws:

    c:\python\python39\lib\abc.py in __new__(mcls, name, bases, namespace, **kwargs)
    104         """
    105         def __new__(mcls, name, bases, namespace, **kwargs):
--> 106             cls = super().__new__(mcls, name, bases, namespace, **kwargs)
    107             _abc_init(cls)
    108             return cls
TypeError: Shiboken.ObjectType.__new__(JsonSettingsQtMeta) is not safe, use type.__new__()

Short example:

from abc import ABCMeta
from dataclasses import dataclass

from PySide6.QtCore import QObject

class JsonSettingsQtMeta(ABCMeta, type(QObject)):

    def __new__(mcls, name, bases, namespace, **kwargs):
        cls = ABCMeta.__new__(mcls, name, bases, namespace, **kwargs)
        return cls

class JsonDeserializable:
    pass

@dataclass
class DesignVariableContainer(QObject, JsonDeserializable, metaclass=JsonSettingsQtMeta):
    pass

I've read through the following bugs, discussions. Attempts to a workaround have failed thus far...

Metaclass conflict when trying to create a Python abstract class that also subclasses a PySide6 class

https://codereview.qt-project.org/gitweb?p=pyside/pyside-setup.git;a=commitdiff;h=cd6172063756a59e02f1a7857bc60a1737214ad1

https://bugreports.qt.io/browse/PYSIDE-1051 https://bugreports.qt.io/browse/PYSIDE-816

0

There are 0 answers