1

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

Fitz
  • 11
  • 2
  • I confirm your problem - I got the same errors. I understand why you need ABCMeta here as I did the same with old python version (<3.8) and PySide2 as inheritance didn't work properly without it. And I didn't touch this part of code after it. Then I got this problem after migration to PySide6. But... I removed ABCMeta and my code works fine with PySide6 and python 3.10. I'm not sure what really helped in my case but if your code also have ABCMeta historically I would propose you to try and play without it. Just as an experiment. – StarterKit Jan 22 '22 at 18:53

0 Answers0