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

AbstractButton's checked default parameter not properly handled in PySide2

    XMLWordPrintable

Details

    • Bug
    • Resolution: Incomplete
    • P3: Somewhat important
    • None
    • 5.13.1, 5.14.1
    • PySide
    • None
    • All

    Description

      The following code snippet prints out errors when attaching a slot to the clicked signal. It seems the checked boolean is not handled properly when there are default arguments in addition to the checked parameter.

       

      import pprint
      
      from PySide2 import QtWidgets, QtCore
      app = QtWidgets.QApplication([])
      
      tb = QtWidgets.QPushButton("Press me!")
      
      # Here, the callback will receive False, since clicked passes a boolean to the lambda.
      tb.clicked.connect(lambda value="lambda with nothing": pprint.pprint(value))
      # Here, the lambda will receive the default value from the checked parameter and NOT the one passed
      # by the lambda
      tb.clicked.connect(lambda checked=False, value="lambda with False": pprint.pprint((value, checked)))
      tb.clicked.connect(lambda checked=True, value="lambda with True": pprint.pprint((value, checked)))
      
      # Here, we get the same behaviour as with the three lambda's above.
      def function_with_nothing(value="function with nothing"):
         pprint.pprint(value)
      tb.clicked.connect(function_with_nothing)
      
      def function_with_false(checked=False, value="function with False"):
         pprint.pprint((value, checked))
      tb.clicked.connect(function_with_false)
      
      def function_with_true(checked=True, value="function with True"):
         pprint.pprint((value, checked))
      tb.clicked.connect(function_with_true)
      
      
      # Those last two callbacks will generate an error when invoked, complaining that
      # TypeError: <lambda>() missing 1 required positional argument: 'checked'
      tb.clicked.connect(lambda checked, value="lambda with checked not set": pprint.pprint((value, checked)))
      
      def function_with_checked_not_set(checked, value="function with checked not set"):
         pprint.pprint((value, checked))
      tb.clicked.connect(function_with_checked_not_set)
      
      # This works however.
      def function_with_checked_only(checked):
         pprint.pprint(("Only checked as a parameter:", checked))
      tb.clicked.connect(function_with_checked_only)
      
      
      tb.show()
      
      app.exec_()
      

      Attachments

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

        Activity

          People

            crmaurei Cristian Maureira-Fredes
            jfboismenu JF Boismenu
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes