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

QModelIndex and QPersistentModelIndex comparison operator type hints are missing

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • Not Evaluated
    • 6.8.1
    • 6.8.0, 6.8.0.1, 6.8.0.2
    • Type hints
    • None
    • 34110468c (dev), 2b9e06b65 (6.8)

    Description

      Problem:

      Although the PySide6 documentation correctly states that QModelIndex and QPersistentModelIndex objects can be compared with each other, the type hints for these classes do not include the ne, lt, le, eq, gt, or ge dunder methods.

      For reference, here is the current QModelIndex type stub as of 6.8.0.1:

      class QModelIndex(Shiboken.Object):
          @typing.overload
          def __init__(self) -> None: ...
          @typing.overload
          def __init__(self, QModelIndex: PySide6.QtCore.QModelIndex) -> None: ...
      
          @staticmethod
          def __copy__() -> None: ...
          @staticmethod
          def __repr__() -> str: ...
          def column(self) -> int: ...
          def const_internal_pointer(self) -> int: ...
          def data(self, role: int = ...) -> typing.Any: ...
          def flags(self) -> PySide6.QtCore.Qt.ItemFlag: ...
          def internal_id(self) -> int: ...
          def internal_pointer(self) -> typing.Any: ...
          def is_valid(self) -> bool: ...
          def model(self) -> PySide6.QtCore.QAbstractItemModel: ...
          def multi_data(self, roleDataSpan: PySide6.QtCore.QModelRoleDataSpan | PySide6.QtCore.QModelRoleData) -> None: ...
          def parent(self) -> PySide6.QtCore.QModelIndex: ...
          def row(self) -> int: ...
          def sibling(self, row: int, column: int) -> PySide6.QtCore.QModelIndex: ...
          def sibling_at_column(self, column: int) -> PySide6.QtCore.QModelIndex: ...
          def sibling_at_row(self, row: int) -> PySide6.QtCore.QModelIndex: ...

      Impact:

      The missing comparison type hints result in type checkers falsely indicating that QModelIndex and QPersistentModelIndex cannot be compared successfully:

      Condition will always evaluate to False since the types "QModelIndex" and "QPersistentModelIndex" have no overlap Pylance(reportUnnecessaryComparison)

      Proposed Solution:

      Based on the type signatures shown in the PySide6 documentation, this type error could be fixed by modifying the QModelIndex and QPersistentModelIndex classes as shown:

      class QModelIndex(Shiboken.Object):
           @typing.overload
           def __init__(self) -> None: ...
           @typing.overload
           def __init__(self, QModelIndex: PySide6.QtCore.QModelIndex) -> None: ...
      
          def __ne__(self, rhs: PySide6.QtCore.QModelIndex | PySide6.QtCore.QPersistentModelIndex) -> bool: ...
          def __lt__(self, rhs: PySide6.QtCore.QModelIndex | PySide6.QtCore.QPersistentModelIndex) -> bool: ...
          def __le__(self, rhs: PySide6.QtCore.QModelIndex | PySide6.QtCore.QPersistentModelIndex) -> bool: ...
          def __eq__(self, rhs: PySide6.QtCore.QModelIndex | PySide6.QtCore.QPersistentModelIndex) -> bool: ...
          def __gt__(self, rhs: PySide6.QtCore.QModelIndex | PySide6.QtCore.QPersistentModelIndex) -> bool: ...
          def __ge__(self, rhs: PySide6.QtCore.QModelIndex | PySide6.QtCore.QPersistentModelIndex) -> bool: ...
      
           @staticmethod
           def __copy__() -> None: ...
           @staticmethod
           def __repr__() -> str: ...
           def column(self) -> int: ...
           def const_internal_pointer(self) -> int: ...
           def data(self, role: int = ...) -> typing.Any: ...
           def flags(self) -> PySide6.QtCore.Qt.ItemFlag: ...
           def internal_id(self) -> int: ...
           def internal_pointer(self) -> typing.Any: ...
           def is_valid(self) -> bool: ...
           def model(self) -> PySide6.QtCore.QAbstractItemModel: ...
           def multi_data(self, roleDataSpan: PySide6.QtCore.QModelRoleDataSpan | PySide6.QtCore.QModelRoleData) -> None: ...
           def parent(self) -> PySide6.QtCore.QModelIndex: ...
           def row(self) -> int: ...
           def sibling(self, row: int, column: int) -> PySide6.QtCore.QModelIndex: ...
           def sibling_at_column(self, column: int) -> PySide6.QtCore.QModelIndex: ...
           def sibling_at_row(self, row: int) -> PySide6.QtCore.QModelIndex: ...

       

      Attachments

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

        Activity

          People

            ctismer Christian Tismer
            bflecker Bryton Flecker
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes