diff --git a/CHANGELOG.md b/CHANGELOG.md index b40f03a8..394ea18f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). * [#184](https://github.com/python-qt-tools/PyQt5-stubs/pull/184) Fix missing module variable detected by latest mypy 0.930 * [#183](https://github.com/python-qt-tools/PyQt5-stubs/pull/183) Add missing operations on QSize +* [#189](https://github.com/python-qt-tools/PyQt5-stubs/pull/189) Fix QListWidget, QTreeWidget and QTableWidget so that their respective items are now optional in many places when used as argument or return value ## 5.15.2.0 ### Added diff --git a/PyQt5-stubs/QtWidgets.pyi b/PyQt5-stubs/QtWidgets.pyi index 10cb7ac0..a03c8dcf 100644 --- a/PyQt5-stubs/QtWidgets.pyi +++ b/PyQt5-stubs/QtWidgets.pyi @@ -7358,15 +7358,15 @@ class QListWidget(QListView): def __init__(self, parent: typing.Optional[QWidget] = ...) -> None: ... - def isPersistentEditorOpen(self, item: QListWidgetItem) -> bool: ... # type: ignore[override] + def isPersistentEditorOpen(self, item: typing.Optional[QListWidgetItem]) -> bool: ... # type: ignore[override] def setSelectionModel(self, selectionModel: QtCore.QItemSelectionModel) -> None: ... - def removeItemWidget(self, aItem: QListWidgetItem) -> None: ... + def removeItemWidget(self, aItem: typing.Optional[QListWidgetItem]) -> None: ... def dropEvent(self, event: QtGui.QDropEvent) -> None: ... def isSortingEnabled(self) -> bool: ... def setSortingEnabled(self, enable: bool) -> None: ... def event(self, e: QtCore.QEvent) -> bool: ... - def itemFromIndex(self, index: QtCore.QModelIndex) -> QListWidgetItem: ... - def indexFromItem(self, item: QListWidgetItem) -> QtCore.QModelIndex: ... + def itemFromIndex(self, index: QtCore.QModelIndex) -> typing.Optional[QListWidgetItem]: ... + def indexFromItem(self, item: typing.Optional[QListWidgetItem]) -> QtCore.QModelIndex: ... def items(self, data: QtCore.QMimeData) -> typing.List[QListWidgetItem]: ... def supportedDropActions(self) -> QtCore.Qt.DropActions: ... def dropMimeData(self, index: int, data: QtCore.QMimeData, action: QtCore.Qt.DropAction) -> bool: ... @@ -7382,46 +7382,46 @@ class QListWidget(QListView): itemDoubleClicked: typing.ClassVar[QtCore.pyqtSignal] itemClicked: typing.ClassVar[QtCore.pyqtSignal] itemPressed: typing.ClassVar[QtCore.pyqtSignal] - def scrollToItem(self, item: QListWidgetItem, hint: QAbstractItemView.ScrollHint = ...) -> None: ... + def scrollToItem(self, item: typing.Optional[QListWidgetItem], hint: QAbstractItemView.ScrollHint = ...) -> None: ... def clear(self) -> None: ... def findItems(self, text: str, flags: typing.Union[QtCore.Qt.MatchFlags, QtCore.Qt.MatchFlag]) -> typing.List[QListWidgetItem]: ... def selectedItems(self) -> typing.List[QListWidgetItem]: ... - def closePersistentEditor(self, item: QListWidgetItem) -> None: ... # type: ignore[override] - def openPersistentEditor(self, item: QListWidgetItem) -> None: ... # type: ignore[override] - def editItem(self, item: QListWidgetItem) -> None: ... + def closePersistentEditor(self, item: typing.Optional[QListWidgetItem]) -> None: ... # type: ignore[override] + def openPersistentEditor(self, item: typing.Optional[QListWidgetItem]) -> None: ... # type: ignore[override] + def editItem(self, item: typing.Optional[QListWidgetItem]) -> None: ... def sortItems(self, order: QtCore.Qt.SortOrder = ...) -> None: ... - def visualItemRect(self, item: QListWidgetItem) -> QtCore.QRect: ... - def setItemWidget(self, item: QListWidgetItem, widget: QWidget) -> None: ... - def itemWidget(self, item: QListWidgetItem) -> QWidget: ... + def visualItemRect(self, item: typing.Optional[QListWidgetItem]) -> QtCore.QRect: ... + def setItemWidget(self, item: typing.Optional[QListWidgetItem], widget: QWidget) -> None: ... + def itemWidget(self, item: typing.Optional[QListWidgetItem]) -> QWidget: ... @typing.overload - def itemAt(self, p: QtCore.QPoint) -> QListWidgetItem: ... + def itemAt(self, p: QtCore.QPoint) -> typing.Optional[QListWidgetItem]: ... @typing.overload - def itemAt(self, ax: int, ay: int) -> QListWidgetItem: ... + def itemAt(self, ax: int, ay: int) -> typing.Optional[QListWidgetItem]: ... @typing.overload def setCurrentRow(self, row: int) -> None: ... @typing.overload def setCurrentRow(self, row: int, command: typing.Union[QtCore.QItemSelectionModel.SelectionFlags, QtCore.QItemSelectionModel.SelectionFlag]) -> None: ... def currentRow(self) -> int: ... @typing.overload - def setCurrentItem(self, item: QListWidgetItem) -> None: ... + def setCurrentItem(self, item: typing.Optional[QListWidgetItem]) -> None: ... @typing.overload - def setCurrentItem(self, item: QListWidgetItem, command: typing.Union[QtCore.QItemSelectionModel.SelectionFlags, QtCore.QItemSelectionModel.SelectionFlag]) -> None: ... - def currentItem(self) -> QListWidgetItem: ... + def setCurrentItem(self, item: typing.Optional[QListWidgetItem], command: typing.Union[QtCore.QItemSelectionModel.SelectionFlags, QtCore.QItemSelectionModel.SelectionFlag]) -> None: ... + def currentItem(self) -> typing.Optional[QListWidgetItem]: ... def __len__(self) -> int: ... def count(self) -> int: ... - def takeItem(self, row: int) -> QListWidgetItem: ... - def addItems(self, labels: typing.Iterable[str]) -> None: ... + def takeItem(self, row: int) -> typing.Optional[QListWidgetItem]: ... + def addItems(self, labels: typing.Iterable[typing.Optional[str]]) -> None: ... @typing.overload - def addItem(self, aitem: QListWidgetItem) -> None: ... + def addItem(self, aitem: typing.Optional[QListWidgetItem]) -> None: ... @typing.overload - def addItem(self, label: str) -> None: ... + def addItem(self, label: typing.Optional[str]) -> None: ... def insertItems(self, row: int, labels: typing.Iterable[str]) -> None: ... @typing.overload - def insertItem(self, row: int, item: QListWidgetItem) -> None: ... + def insertItem(self, row: int, item: typing.Optional[QListWidgetItem]) -> None: ... @typing.overload def insertItem(self, row: int, label: str) -> None: ... - def row(self, item: QListWidgetItem) -> int: ... - def item(self, row: int) -> QListWidgetItem: ... + def row(self, item: typing.Optional[QListWidgetItem]) -> int: ... + def item(self, row: int) -> typing.Optional[QListWidgetItem]: ... class QMainWindow(QWidget): @@ -10588,11 +10588,11 @@ class QTableWidget(QTableView): @typing.overload def __init__(self, rows: int, columns: int, parent: typing.Optional[QWidget] = ...) -> None: ... - def isPersistentEditorOpen(self, item: QTableWidgetItem) -> bool: ... # type: ignore[override] + def isPersistentEditorOpen(self, item: typing.Optional[QTableWidgetItem]) -> bool: ... # type: ignore[override] def dropEvent(self, event: QtGui.QDropEvent) -> None: ... def event(self, e: QtCore.QEvent) -> bool: ... - def itemFromIndex(self, index: QtCore.QModelIndex) -> QTableWidgetItem: ... - def indexFromItem(self, item: QTableWidgetItem) -> QtCore.QModelIndex: ... + def itemFromIndex(self, index: QtCore.QModelIndex) -> typing.Optional[QTableWidgetItem]: ... + def indexFromItem(self, item: typing.Optional[QTableWidgetItem]) -> QtCore.QModelIndex: ... def items(self, data: QtCore.QMimeData) -> typing.List[QTableWidgetItem]: ... def supportedDropActions(self) -> QtCore.Qt.DropActions: ... def dropMimeData(self, row: int, column: int, data: QtCore.QMimeData, action: QtCore.Qt.DropAction) -> bool: ... @@ -10619,14 +10619,14 @@ class QTableWidget(QTableView): def removeRow(self, row: int) -> None: ... def insertColumn(self, column: int) -> None: ... def insertRow(self, row: int) -> None: ... - def scrollToItem(self, item: QTableWidgetItem, hint: QAbstractItemView.ScrollHint = ...) -> None: ... - def setItemPrototype(self, item: QTableWidgetItem) -> None: ... - def itemPrototype(self) -> QTableWidgetItem: ... - def visualItemRect(self, item: QTableWidgetItem) -> QtCore.QRect: ... + def scrollToItem(self, item: typing.Optional[QTableWidgetItem], hint: QAbstractItemView.ScrollHint = ...) -> None: ... + def setItemPrototype(self, item: typing.Optional[QTableWidgetItem]) -> None: ... + def itemPrototype(self) -> typing.Optional[QTableWidgetItem]: ... + def visualItemRect(self, item: typing.Optional[QTableWidgetItem]) -> QtCore.QRect: ... @typing.overload - def itemAt(self, p: QtCore.QPoint) -> QTableWidgetItem: ... + def itemAt(self, p: QtCore.QPoint) -> typing.Optional[QTableWidgetItem]: ... @typing.overload - def itemAt(self, ax: int, ay: int) -> QTableWidgetItem: ... + def itemAt(self, ax: int, ay: int) -> typing.Optional[QTableWidgetItem]: ... def visualColumn(self, logicalColumn: int) -> int: ... def visualRow(self, logicalRow: int) -> int: ... def findItems(self, text: str, flags: typing.Union[QtCore.Qt.MatchFlags, QtCore.Qt.MatchFlag]) -> typing.List[QTableWidgetItem]: ... @@ -10635,10 +10635,10 @@ class QTableWidget(QTableView): def setRangeSelected(self, range: QTableWidgetSelectionRange, select: bool) -> None: ... def removeCellWidget(self, arow: int, acolumn: int) -> None: ... def setCellWidget(self, row: int, column: int, widget: QWidget) -> None: ... - def cellWidget(self, row: int, column: int) -> QWidget: ... - def closePersistentEditor(self, item: QTableWidgetItem) -> None: ... # type: ignore[override] - def openPersistentEditor(self, item: QTableWidgetItem) -> None: ... # type: ignore[override] - def editItem(self, item: QTableWidgetItem) -> None: ... + def cellWidget(self, row: int, column: int) -> typing.List[QWidget]: ... + def closePersistentEditor(self, item: typing.Optional[QTableWidgetItem]) -> None: ... # type: ignore[override] + def openPersistentEditor(self, item: typing.Optional[QTableWidgetItem]) -> None: ... # type: ignore[override] + def editItem(self, item: typing.Optional[QTableWidgetItem]) -> None: ... def isSortingEnabled(self) -> bool: ... def setSortingEnabled(self, enable: bool) -> None: ... def sortItems(self, column: int, order: QtCore.Qt.SortOrder = ...) -> None: ... @@ -10647,25 +10647,25 @@ class QTableWidget(QTableView): @typing.overload def setCurrentCell(self, row: int, column: int, command: typing.Union[QtCore.QItemSelectionModel.SelectionFlags, QtCore.QItemSelectionModel.SelectionFlag]) -> None: ... @typing.overload - def setCurrentItem(self, item: QTableWidgetItem) -> None: ... + def setCurrentItem(self, item: typing.Optional[QTableWidgetItem]) -> None: ... @typing.overload - def setCurrentItem(self, item: QTableWidgetItem, command: typing.Union[QtCore.QItemSelectionModel.SelectionFlags, QtCore.QItemSelectionModel.SelectionFlag]) -> None: ... - def currentItem(self) -> QTableWidgetItem: ... + def setCurrentItem(self, item: typing.Optional[QTableWidgetItem], command: typing.Union[QtCore.QItemSelectionModel.SelectionFlags, QtCore.QItemSelectionModel.SelectionFlag]) -> None: ... + def currentItem(self) -> typing.Optional[QTableWidgetItem]: ... def currentColumn(self) -> int: ... def currentRow(self) -> int: ... def setHorizontalHeaderLabels(self, labels: typing.Iterable[str]) -> None: ... def setVerticalHeaderLabels(self, labels: typing.Iterable[str]) -> None: ... - def takeHorizontalHeaderItem(self, column: int) -> QTableWidgetItem: ... - def setHorizontalHeaderItem(self, column: int, item: QTableWidgetItem) -> None: ... - def horizontalHeaderItem(self, column: int) -> QTableWidgetItem: ... - def takeVerticalHeaderItem(self, row: int) -> QTableWidgetItem: ... - def setVerticalHeaderItem(self, row: int, item: QTableWidgetItem) -> None: ... - def verticalHeaderItem(self, row: int) -> QTableWidgetItem: ... - def takeItem(self, row: int, column: int) -> QTableWidgetItem: ... - def setItem(self, row: int, column: int, item: QTableWidgetItem) -> None: ... - def item(self, row: int, column: int) -> QTableWidgetItem: ... - def column(self, item: QTableWidgetItem) -> int: ... - def row(self, item: QTableWidgetItem) -> int: ... + def takeHorizontalHeaderItem(self, column: int) -> typing.Optional[QTableWidgetItem]: ... + def setHorizontalHeaderItem(self, column: int, item: typing.Optional[QTableWidgetItem]) -> None: ... + def horizontalHeaderItem(self, column: int) -> typing.Optional[QTableWidgetItem]: ... + def takeVerticalHeaderItem(self, row: int) -> typing.Optional[QTableWidgetItem]: ... + def setVerticalHeaderItem(self, row: int, item: typing.Optional[QTableWidgetItem]) -> None: ... + def verticalHeaderItem(self, row: int) -> typing.Optional[QTableWidgetItem]: ... + def takeItem(self, row: int, column: int) -> typing.Optional[QTableWidgetItem]: ... + def setItem(self, row: int, column: int, item: typing.Optional[QTableWidgetItem]) -> None: ... + def item(self, row: int, column: int) -> typing.Optional[QTableWidgetItem]: ... + def column(self, item: typing.Optional[QTableWidgetItem]) -> int: ... + def row(self, item: typing.Optional[QTableWidgetItem]) -> int: ... def columnCount(self) -> int: ... def setColumnCount(self, columns: int) -> None: ... def rowCount(self) -> int: ... @@ -11383,22 +11383,22 @@ class QTreeWidget(QTreeView): def __init__(self, parent: typing.Optional[QWidget] = ...) -> None: ... - def isPersistentEditorOpen(self, item: QTreeWidgetItem, column: int = ...) -> bool: ... # type: ignore[override] + def isPersistentEditorOpen(self, item: typing.Optional[QTreeWidgetItem], column: int = ...) -> bool: ... # type: ignore[override] def setSelectionModel(self, selectionModel: QtCore.QItemSelectionModel) -> None: ... - def removeItemWidget(self, item: QTreeWidgetItem, column: int) -> None: ... - def itemBelow(self, item: QTreeWidgetItem) -> QTreeWidgetItem: ... - def itemAbove(self, item: QTreeWidgetItem) -> QTreeWidgetItem: ... - def setFirstItemColumnSpanned(self, item: QTreeWidgetItem, span: bool) -> None: ... - def isFirstItemColumnSpanned(self, item: QTreeWidgetItem) -> bool: ... + def removeItemWidget(self, item: typing.Optional[QTreeWidgetItem], column: int) -> None: ... + def itemBelow(self, item: typing.Optional[QTreeWidgetItem]) -> typing.Optional[QTreeWidgetItem]: ... + def itemAbove(self, item: typing.Optional[QTreeWidgetItem]) -> typing.Optional[QTreeWidgetItem]: ... + def setFirstItemColumnSpanned(self, item: typing.Optional[QTreeWidgetItem], span: bool) -> None: ... + def isFirstItemColumnSpanned(self, item: typing.Optional[QTreeWidgetItem]) -> bool: ... def setHeaderLabel(self, alabel: str) -> None: ... def invisibleRootItem(self) -> QTreeWidgetItem: ... def dropEvent(self, event: QtGui.QDropEvent) -> None: ... def event(self, e: QtCore.QEvent) -> bool: ... - def itemFromIndex(self, index: QtCore.QModelIndex) -> QTreeWidgetItem: ... - def indexFromItem(self, item: QTreeWidgetItem, column: int = ...) -> QtCore.QModelIndex: ... + def itemFromIndex(self, index: QtCore.QModelIndex) -> typing.Optional[QTreeWidgetItem]: ... + def indexFromItem(self, item: typing.Optional[QTreeWidgetItem], column: int = ...) -> QtCore.QModelIndex: ... def supportedDropActions(self) -> QtCore.Qt.DropActions: ... - def dropMimeData(self, parent: QTreeWidgetItem, index: int, data: QtCore.QMimeData, action: QtCore.Qt.DropAction) -> bool: ... - def mimeData(self, items: typing.Iterable[QTreeWidgetItem]) -> QtCore.QMimeData: ... + def dropMimeData(self, parent: typing.Optional[QTreeWidgetItem], index: int, data: QtCore.QMimeData, action: QtCore.Qt.DropAction) -> bool: ... + def mimeData(self, items: typing.Iterable[typing.Optional[QTreeWidgetItem]]) -> QtCore.QMimeData: ... def mimeTypes(self) -> typing.List[str]: ... itemSelectionChanged: typing.ClassVar[QtCore.pyqtSignal] currentItemChanged: typing.ClassVar[QtCore.pyqtSignal] @@ -11411,42 +11411,42 @@ class QTreeWidget(QTreeView): itemClicked: typing.ClassVar[QtCore.pyqtSignal] itemPressed: typing.ClassVar[QtCore.pyqtSignal] def clear(self) -> None: ... - def collapseItem(self, item: QTreeWidgetItem) -> None: ... - def expandItem(self, item: QTreeWidgetItem) -> None: ... - def scrollToItem(self, item: QTreeWidgetItem, hint: QAbstractItemView.ScrollHint = ...) -> None: ... + def collapseItem(self, item: typing.Optional[QTreeWidgetItem]) -> None: ... + def expandItem(self, item: typing.Optional[QTreeWidgetItem]) -> None: ... + def scrollToItem(self, item: typing.Optional[QTreeWidgetItem], hint: QAbstractItemView.ScrollHint = ...) -> None: ... def findItems(self, text: str, flags: typing.Union[QtCore.Qt.MatchFlags, QtCore.Qt.MatchFlag], column: int = ...) -> typing.List[QTreeWidgetItem]: ... def selectedItems(self) -> typing.List[QTreeWidgetItem]: ... - def setItemWidget(self, item: QTreeWidgetItem, column: int, widget: QWidget) -> None: ... - def itemWidget(self, item: QTreeWidgetItem, column: int) -> QWidget: ... - def closePersistentEditor(self, item: QTreeWidgetItem, column: int = ...) -> None: ... # type: ignore[override] - def openPersistentEditor(self, item: QTreeWidgetItem, column: int = ...) -> None: ... # type: ignore[override] - def editItem(self, item: QTreeWidgetItem, column: int = ...) -> None: ... + def setItemWidget(self, item: typing.Optional[QTreeWidgetItem], column: int, widget: QWidget) -> None: ... + def itemWidget(self, item: typing.Optional[QTreeWidgetItem], column: int) -> QWidget: ... + def closePersistentEditor(self, item: typing.Optional[QTreeWidgetItem], column: int = ...) -> None: ... # type: ignore[override] + def openPersistentEditor(self, item: typing.Optional[QTreeWidgetItem], column: int = ...) -> None: ... # type: ignore[override] + def editItem(self, item: typing.Optional[QTreeWidgetItem], column: int = ...) -> None: ... def sortItems(self, column: int, order: QtCore.Qt.SortOrder) -> None: ... def sortColumn(self) -> int: ... - def visualItemRect(self, item: QTreeWidgetItem) -> QtCore.QRect: ... + def visualItemRect(self, item: typing.Optional[QTreeWidgetItem]) -> QtCore.QRect: ... @typing.overload - def itemAt(self, p: QtCore.QPoint) -> QTreeWidgetItem: ... + def itemAt(self, p: QtCore.QPoint) -> typing.Optional[QTreeWidgetItem]: ... @typing.overload - def itemAt(self, ax: int, ay: int) -> QTreeWidgetItem: ... + def itemAt(self, ax: int, ay: int) -> typing.Optional[QTreeWidgetItem]: ... @typing.overload - def setCurrentItem(self, item: QTreeWidgetItem) -> None: ... + def setCurrentItem(self, item: typing.Optional[QTreeWidgetItem]) -> None: ... @typing.overload - def setCurrentItem(self, item: QTreeWidgetItem, column: int) -> None: ... + def setCurrentItem(self, item: typing.Optional[QTreeWidgetItem], column: int) -> None: ... @typing.overload - def setCurrentItem(self, item: QTreeWidgetItem, column: int, command: typing.Union[QtCore.QItemSelectionModel.SelectionFlags, QtCore.QItemSelectionModel.SelectionFlag]) -> None: ... + def setCurrentItem(self, item: typing.Optional[QTreeWidgetItem], column: int, command: typing.Union[QtCore.QItemSelectionModel.SelectionFlags, QtCore.QItemSelectionModel.SelectionFlag]) -> None: ... def currentColumn(self) -> int: ... - def currentItem(self) -> QTreeWidgetItem: ... + def currentItem(self) -> typing.Optional[QTreeWidgetItem]: ... def setHeaderLabels(self, labels: typing.Iterable[str]) -> None: ... - def setHeaderItem(self, item: QTreeWidgetItem) -> None: ... - def headerItem(self) -> QTreeWidgetItem: ... + def setHeaderItem(self, item: typing.Optional[QTreeWidgetItem]) -> None: ... + def headerItem(self) -> typing.Optional[QTreeWidgetItem]: ... def addTopLevelItems(self, items: typing.Iterable[QTreeWidgetItem]) -> None: ... def insertTopLevelItems(self, index: int, items: typing.Iterable[QTreeWidgetItem]) -> None: ... - def indexOfTopLevelItem(self, item: QTreeWidgetItem) -> int: ... - def takeTopLevelItem(self, index: int) -> QTreeWidgetItem: ... - def addTopLevelItem(self, item: QTreeWidgetItem) -> None: ... - def insertTopLevelItem(self, index: int, item: QTreeWidgetItem) -> None: ... + def indexOfTopLevelItem(self, item: typing.Optional[QTreeWidgetItem]) -> int: ... + def takeTopLevelItem(self, index: int) -> typing.Optional[QTreeWidgetItem]: ... + def addTopLevelItem(self, item: typing.Optional[QTreeWidgetItem]) -> None: ... + def insertTopLevelItem(self, index: int, item: typing.Optional[QTreeWidgetItem]) -> None: ... def topLevelItemCount(self) -> int: ... - def topLevelItem(self, index: int) -> QTreeWidgetItem: ... + def topLevelItem(self, index: int) -> typing.Optional[QTreeWidgetItem]: ... def setColumnCount(self, columns: int) -> None: ... def columnCount(self) -> int: ...