Uploaded image for project: 'Qt for Python'
  1. Qt for Python
  2. PYSIDE-816

Unable to call type(QtWidgets.QWidget).__new__ in Python 2.7

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P2: Important
    • 5.12.4
    • 5.11.1, 5.11.2
    • PySide, Shiboken
    • None
    • dc14eba3040b24f538b7fce93a463d1f0a511bc4 (pyside/pyside-setup/dev)

    Description

      We have a metaclass based on type(QtWidgets.QWidget) – which resolves to Shiboken.ObjectType – that we've had in production dating back to PySide/Qt4 that's breaking in the versions of PySide2 that are on pypi (5.11.x). Earlier alpha versions of PySide2 (2.0.0~alpha0) do not have this problem.

      If you call the following from Python 2.7 using a 5.11.x version of PySide2, you'll see that it appears as though Shiboken.ObjectType is passing through arguments it's given to type.__new__, which isn't allowed.

      This line of code is contrived just to illustrate the problem, hence the empty name, parents, and class_dict arguments, and passing the type in as-is. In our production code, that would be the metaclass we're defining, and the remaining arguments would be passed through from input args/kwargs:

      type(QtWidgets.QWidget).__new__(type(QtWidgets.QWidget), "", (), {})
      

      In PySide2 5.11.x, the following is raised:

      TypeError: Shiboken.ObjectType.__new__(Shiboken.ObjectType) is not safe, use type.__new__()
      

      In PySide/Qt4 or PySide2 2.0.0~alpha0, the correct return occurs:

      <class '__main__.'>
      

      We're unsure whether this is a bug, or if it's intentional behavior and we're simply doing something that's incorrect by today's standards. Some guidance here would be appreciated!

      Attachments

        1. pyside_metaclass_test.py
          0.2 kB
        2. pyside816_core.py
          0.6 kB
        3. pyside816.py
          0.6 kB

        Issue Links

          For Gerrit Dashboard: PYSIDE-816
          # Subject Branch Project Status CR V

          Activity

            People

              ctismer Christian Tismer
              jbee Jeff Beeland
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes