Skip to content

Commit 66a0fad

Browse files
committed
Work around apparent false positive mypy bug.
Mypy is flagging contextMenuEvent signature problems. This method does not have an optional event parameter. See: * python/mypy#16437 * https://doc.qt.io/qt-6/qwidget.html#contextMenuEvent * https://wiki.python.org/moin/PyQt/Handling%20context%20menus The mypy error looks like this: setoolsgui/widgets/views/treewidget.py:15: error: Argument 1 of "contextMenuEvent" is incompatible with supertype "QAbstractScrollArea"; supertype defines the argument type as "QContextMenuEvent | None" [override] def contextMenuEvent(self, event: QtGui.QContextMenuEvent) -> None: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ setoolsgui/widgets/views/treewidget.py:15: note: This violates the Liskov substitution principle setoolsgui/widgets/views/treewidget.py:15: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#incompatible-overrides setoolsgui/widgets/views/treewidget.py:15: error: Argument 1 of "contextMenuEvent" is incompatible with supertype "QWidget"; supertype defines the argument type as "QContextMenuEvent | None" [override] def contextMenuEvent(self, event: QtGui.QContextMenuEvent) -> None: Signed-off-by: Chris PeBenito <[email protected]>
1 parent 06786d3 commit 66a0fad

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

setoolsgui/widgets/views/listview.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def set_selection(self, selections: list[str]) -> None:
5151
#
5252
# Overridden methods
5353
#
54-
def contextMenuEvent(self, event: QtGui.QContextMenuEvent) -> None:
54+
def contextMenuEvent(self, event: QtGui.QContextMenuEvent) -> None: # type: ignore[override]
5555
"""Handle the context menu event."""
5656
menu = QtWidgets.QMenu(self)
5757
menu.setAttribute(QtCore.Qt.WidgetAttribute.WA_DeleteOnClose)

setoolsgui/widgets/views/tableview.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class SEToolsTableView(QtWidgets.QTableView):
1919
provided by the model.
2020
"""
2121

22-
def contextMenuEvent(self, event: QtGui.QContextMenuEvent) -> None:
22+
def contextMenuEvent(self, event: QtGui.QContextMenuEvent) -> None: # type: ignore[override]
2323
"""Handle the context menu event."""
2424
menu = QtWidgets.QMenu(self)
2525
menu.setAttribute(QtCore.Qt.WidgetAttribute.WA_DeleteOnClose)

setoolsgui/widgets/views/treewidget.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class SEToolsTreeWidget(QtWidgets.QTreeWidget):
1212

1313
"""QTreeWidget class extended for SETools use."""
1414

15-
def contextMenuEvent(self, event: QtGui.QContextMenuEvent) -> None:
15+
def contextMenuEvent(self, event: QtGui.QContextMenuEvent) -> None: # type: ignore[override]
1616
"""Handle the context menu event."""
1717
copy_tree_action = QtGui.QAction("Copy Tree...", self)
1818
copy_tree_action.triggered.connect(self.copy)

0 commit comments

Comments
 (0)