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

Type hints should indicate optionality

    XMLWordPrintable

Details

    • Windows
    • db81f0cb8 (dev), 065d84a16 (6.8), 19d114233 (dev), 3677c9244 (6.8)

    Description

      QtWidgets.pyi indicates that QApplication.activeModalWidget returns a QWidget:

      def activeModalWidget() -> PySide6.QtWidgets.QWidget: ...
      

      However, this code demonstrates that activeModalWidget can also return None:

      from PySide6.QtWidgets import QApplication
      app = QApplication()
      widget = app.activeModalWidget()
      print(type(widget))  # prints "<class 'NoneType'>"
      

      So the correct type hint would be

      [...] -> PySide6.QtWidgets.QWidget | None: ...
      

      The same is true for many other functions, one example being QTableWidget.item.

      Attachments

        Issue Links

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

          Activity

            People

              ctismer Christian Tismer
              bers bers bers
              Votes:
              3 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: