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

Type Hinting: Expose signals / "clicked" member variable in stub to avoid erros in static type checkers

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Duplicate
    • Not Evaluated
    • None
    • 6.3.0
    • PySide
    • None
    • Linux/Wayland, Linux/X11, Linux/Yocto, Linux/Other display system, macOS, Windows

    Description

      I'm using PySide version 6.3.0 and in this version if you are using a static type checker, e.g., pyright, and access a member variable like "clicked", you will get a bunch of false positive errors saying the member variable doesn't exist.

      Here is an example code:

      import sys
      from PySide6 import QtCore, QtWidgets, QtGui
      
      
      class HelloWorld(QtWidgets.QWidget):
          def __init__(self):
              super().__init__()
      
              self.button = QtWidgets.QPushButton("Push me!")
              self.button.clicked.connect(self.magic)
      
          @QtCore.Slot()
          def magic(self):
              print("magic")
      
      
      def run():
          app = QtWidgets.QApplication()
      
          widget = HelloWorld()
          widget.setWindowTitle("Hello World!")
          widget.resize(500, 500)
          widget.show()
      
          sys.exit(app.exec())
      

       

      And the output of pyright:

      No configuration file found.
      pyproject.toml file found at /home/labatata/Code/Python/tim-gui.
      Loading pyproject.toml file at /home/labatata/Code/Python/tim-gui/pyproject.toml
      Pyproject file "/home/labatata/Code/Python/tim-gui/pyproject.toml" is missing "[tool.pyright]" section.
      stubPath /home/labatata/Code/Python/tim-gui/typings is not a valid directory.
      Assuming Python platform Linux
      Searching for source files
      Found 1 source file
      /home/labatata/Code/Python/tim-gui/tim_gui/gui/__init__.py
        /home/labatata/Code/Python/tim-gui/tim_gui/gui/__init__.py:16:21 - error: Cannot access member "clicked" for type
      "QPushButton"
          Member "clicked" is unknown (reportGeneralTypeIssues)
      1 error, 0 warnings, 0 informations
      Completed in 2.1sec
      

      I think the solution here would be to expose these members variables in the stub files.

      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved: