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

Type hints should indicate optionality

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P4: Low
    • Some future version
    • 6.5.2
    • Type hints
    • None
    • Windows

    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

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

          Activity

            People

              adherrma Adrian Herrmann
              bers bers bers
              Votes:
              3 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There are no open Gerrit changes