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

Signature of objects with __call__ method incorrectly inspected on signal connect

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • Not Evaluated
    • None
    • 6.x, 5.15.9
    • PySide
    • None
    • macOS
    • fe057b441 (dev), 7c77ccc08 (6.6), c44b7409a (6.5)

    Description

      It appears that the call signature of callable objects (i.e. objects with a _call_ method that aren't functions or bound methods) is not being correctly inspected during signalInstanceConnect. So, if they accept less arguments than the signal emits, an exception occurs during emit. This is the case with both PySide6 and PySide2, but is not the case with PyQt5/6. It does work, however, if you connect to the

      __call__

      method directly

      Example:

      # from PyQt5.QtCore import QObject, pyqtSignal as Signal  # works
      # from PyQt6.QtCore import QObject, pyqtSignal as Signal  # works
      # from PySide2.QtCore import QObject, Signal              # breaks
      from PySide6.QtCore import QObject, Signal                # breaks
      
      
      class Emitter(QObject):
          sig = Signal(int, int)
      
      
      class MyObj:
          def __call__(self, x: int):
              print(locals())
      
      
      emitter = Emitter()
      obj = MyObj()
      emitter.sig.connect(obj)  # they ALL work if you connect to obj.__call__
      emitter.sig.emit(1, 2)
      

      raises

      TypeError: MyObj.__call__() takes 2 positional arguments but 3 were given
      

      Attachments

        Issue Links

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

          Activity

            People

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

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There is 1 open Gerrit change