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

typing: QTreeWidget.topLevelItem() may return None

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Fixed
    • Not Evaluated
    • 6.9.0, 6.10.0
    • 6.8.2
    • Type hints
    • None
    • c16d08c5e (dev), 7695f3b2f (6.9), 1c2d0bf41 (6.8)

    Description

      According to documenation : https://doc.qt.io/qt-6/qtreewidget.html#topLevelItem

      QTreeWidget.topLevelItem() may return None if the item is not found.

      But current types describes the return value as QTreeWidgetItem instead of Optional[QTreeWidgetItem]

      The current  typing can lead to incorrect code, where the developers assumes (with the support of type-checking) that an actual widget is always returned, and forgets to check for None. This is precisely the kind of errors for which we want to use typing, to not miss a potential None

      (reported on PySide6-stubs)

      Attachments

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

        Activity

          People

            ctismer Christian Tismer
            bluebird75 Philippe Fremy
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: