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

Signal connections to functools.partial use wrong signature

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Won't Do
    • Icon: P2: Important P2: Important
    • None
    • 6.9.0
    • PySide
    • None

      Scenario:

      • Signal has int parameter
      • Slot has bool parameter
      • Expectation is that functools.partial(self.slot, test=True) should somehow fit, ignoring the int

      This snippet:

      import functools
      
      from PySide6.QtCore import QObject, Signal, Slot
      
      class Test(QObject):
      
          sig = Signal(int)
      
          def __init__(self, parent=None):
              super().__init__(parent)
              self.sig.connect(functools.partial(self.slot, test=True))
      
          # @Slot()
          def slot(self, test):
              pass
      
      
      t = Test()
      t.sig.emit(42)
      

      results in:

      TypeError: Test.slot() got multiple values for argument 'test'
      

      or, when making test a keyword-only argument:

      TypeError: Test.slot() takes 1 positional argument but 2 positional arguments (and 1 keyword-only argument) were given
      

      ( seterror_argument(), sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/errorhandler.py:118 )

      but works with PyQt6 (and in PySide6 when removing the keyword argument and functools.partial).

      I'd expect PySide to detect the signature of the partial object and call the slot with no arguments (like with a regular function). Right now it seems to assume the signature of the wrapped function or something?

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            crmaurei Cristian Maureira-Fredes
            the compiler Florian Bruhin
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes