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

Unable to call QtCore.QObject.__new__ in Python 2.7

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P2: Important
    • 5.13.1
    • 5.12.4, 5.13.0
    • PySide, Shiboken
    • All
    • cd6172063756a59e02f1a7857bc60a1737214ad1 (pyside/pyside-setup/5.13) 0add41759ad3346a8ea93863e347e73e98700bec (pyside/pyside-setup/5.12)

    Description

      We have a singleton metaclass based on type(QtCore.QObject) in the __call__
      method we create a new instance of the class and return it

      def __call__(self, *args, **kwargs):
          instance = self.__new__(self, *args, **kwargs)
          instance.__init__(*args, **kwargs)
          return instance

      or, if you want the one-liner version:

      QtCore.QObject.__new__(QtCore.QObject, "", (), {})

      the error obtained running this code on Python2 is:

      TypeError: PySide2.QtCore.QObject.__new__(PySide2.QtCore.QObject) is not safe, use object.__new__()

      the same one-liner works on Python3, I think it is related to PYSIDE-816 and heap types.

      Attachments

        Issue Links

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

          Activity

            People

              ctismer Christian Tismer
              qtlavoratore Nicolo' Cristini
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes