Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failure when using six.with_metaclass in python 2.7 when metaclass doesn't directly inherit from type #373

Open
herronelou opened this issue Apr 19, 2023 · 0 comments

Comments

@herronelou
Copy link

Hello.

I've been trying really hard to make a class with a new metaclass in a way that's compatible with both python 2 and 3, and ran into issues both while using six.with_metaclass and future.utils.with_metaclass which is a little bit different. I'm happy to report that the six.add_metaclass decorator did the job, however.

Now I'm sure with_metaclass works fine in most cases, but here is the situation:

I'm using the library PySide2 https://pypi.org/project/PySide2/

I'm trying to subclass a PySide2.QtCore.QObject with a new metaclass. For this, I need my metaclass to inherit from the original metaclass of QObject, which is Shiboken.ObjectType.

I then try to define my class with the new meta, which fails because with_metaclass attempts to use type.__new__ directly, instead of Shiboken.ObjectType.__new__

from PySide2 import QtCore
from six import with_metaclass


class MyMeta(type(QtCore.QObject)):
    pass

class MyClass(with_metaclass(MyMeta, QtCore.QObject)):
    pass
TypeError: type.__new__(metaclass) is not safe, use Shiboken.ObjectType.__new__()

It does work fine in Python 3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant