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

SystemError on decorating an existing method with Slot

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Invalid
    • Icon: Not Evaluated Not Evaluated
    • None
    • 6.6.0
    • PySide
    • None
    • Windows

      I inherit from a class that does not mark its methods with Slot(), which I want to fix during inheritance. Related: How can one attach a decorator to a function "after the fact" in python? - Stack Overflow

      This is the code I tried:

      from PySide6.QtCore import QObject, Signal, Slot
      
      class SuperReceiver(QObject):
          def receive(self):
              print("Received")
      
      class Receiver(SuperReceiver, QObject):
          def __new__(cls):
              instance = super().__new__(cls)
              # SystemError: <PySide6.QtCore.Slot object at 0x000002004E6A9910> returned a result with an exception set
              instance.receive = Slot()(instance.receive)
              # Workaround:
              # instance.receive = Slot()(lambda slot=instance.receive: slot())
              return instance
      
      class Signaler(QObject):
          signal = Signal()
      
      receiver = Receiver()
      signaler = Signaler()
      signaler.signal.connect(receiver.receive)
      signaler.signal.emit()
      print("Done")
      

       

      However, I am getting a SystemError: <PySide6.QtCore.Slot object at 0x00000190DB949910> returned a result with an exception set
       
      I found a workaround by wrapping the existing method in a lambda, and using that as a decorated slot. It seems to work fine, so I think the overall approach is fine. I just wonder why "instance.receive = Slot()(instance.receive)" doesn't simply work. I think it should.

        1. pyside2512_diag.diff
          3 kB
          Friedemann Kleint
        2. pyside2512.py
          0.6 kB
          Friedemann Kleint
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            crmaurei Cristian Maureira-Fredes
            bers bers bers
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes