Skip to content

Commit

Permalink
Add PyQt6 to tox -e mypy (#6170)
Browse files Browse the repository at this point in the history
This should allows mypy to infer more types.

Discussed in
#5897 (comment)

---------

Co-authored-by: Grzegorz Bokota <bokota+github@gmail.com>
Co-authored-by: napari-bot <napari-bot@users.noreply.github.com>
  • Loading branch information
3 people committed Oct 16, 2023
1 parent 72538e5 commit 591809d
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 9 deletions.
9 changes: 7 additions & 2 deletions napari/_qt/containers/qt_layer_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,21 @@ def __init__(
# To be able to update the loading indicator frame in the item delegate
# smoothly and also be able to leave the item painted in a coherent
# state (showing the loading indicator or the thumbnail)
layer_delegate.loading_frame_changed.connect(self.viewport().update)
viewport = self.viewport()
assert viewport is not None

layer_delegate.loading_frame_changed.connect(viewport.update)

self.setToolTip(trans._('Layer list'))

# This reverses the order of the items in the view,
# so items at the end of the list are at the top.
self.setModel(ReverseProxyModel(self.model()))

def keyPressEvent(self, e: QKeyEvent) -> None:
def keyPressEvent(self, e: Optional[QKeyEvent]) -> None:
"""Override Qt event to pass events to the viewer."""
if e is None:
return
if e.key() != Qt.Key.Key_Space:
super().keyPressEvent(e)
if e.key() not in (Qt.Key.Key_Backspace, Qt.Key.Key_Delete):
Expand Down
2 changes: 1 addition & 1 deletion napari/components/_viewer_key_bindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,5 +166,5 @@ def hold_for_pan_zoom(viewer: ViewerModel):
def show_shortcuts(viewer: Viewer):
pref_list = viewer.window._open_preferences_dialog()._list
for i in range(pref_list.count()):
if pref_list.item(i).text() == "Shortcuts":
if (item := pref_list.item(i)) and item.text() == "Shortcuts":
pref_list.setCurrentRow(i)
4 changes: 3 additions & 1 deletion napari/plugins/_npe2.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from npe2.manifest.contributions import WriterContribution
from npe2.plugin_manager import PluginName
from npe2.types import LayerData, SampleDataCreator, WidgetCreator
from qtpy.QtWidgets import QMenu # type: ignore [attr-defined]
from qtpy.QtWidgets import QMenu

from napari.layers import Layer
from napari.types import SampleDict
Expand Down Expand Up @@ -163,10 +163,12 @@ def _wrapped(*args):
if isinstance(item, contributions.Submenu):
subm_contrib = pm.get_submenu(item.submenu)
subm = menu.addMenu(subm_contrib.label)
assert subm is not None
populate_qmenu(subm, subm_contrib.id)
else:
cmd = pm.get_command(item.command)
action = menu.addAction(cmd.title)
assert action is not None
action.triggered.connect(_wrap(cmd))


Expand Down
2 changes: 1 addition & 1 deletion napari/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import dask.array # noqa: ICN001
import zarr
from magicgui.widgets import FunctionGui
from qtpy.QtWidgets import QWidget # type: ignore [attr-defined]
from qtpy.QtWidgets import QWidget


__all__ = [
Expand Down
1 change: 1 addition & 0 deletions resources/requirements_mypy.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ numpy
npe2
pydantic
qtpy
pyqt6
types-PyYAML
types-setuptools
types-requests
14 changes: 10 additions & 4 deletions resources/requirements_mypy.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ appdirs==1.4.4
# via npe2
build==0.10.0
# via npe2
click==8.1.6
click==8.1.7
# via typer
docstring-parser==0.15
# via magicgui
Expand All @@ -33,7 +33,7 @@ packaging==23.1
# build
# qtpy
# superqt
psygnal==0.9.2
psygnal==0.9.3
# via
# magicgui
# npe2
Expand All @@ -47,6 +47,12 @@ pygments==2.16.1
# superqt
pyproject-hooks==1.0.0
# via build
pyqt6==6.5.2
# via -r resources/requirements_mypy.in
pyqt6-qt6==6.5.2
# via pyqt6
pyqt6-sip==13.5.2
# via pyqt6
pyyaml==6.0.1
# via npe2
qtpy==2.3.1
Expand All @@ -56,7 +62,7 @@ qtpy==2.3.1
# superqt
rich==13.5.2
# via npe2
superqt==0.5.0
superqt==0.5.2
# via magicgui
tomli-w==1.0.0
# via npe2
Expand All @@ -66,7 +72,7 @@ types-pyyaml==6.0.12.11
# via -r resources/requirements_mypy.in
types-requests==2.31.0.2
# via -r resources/requirements_mypy.in
types-setuptools==68.0.0.3
types-setuptools==68.1.0.0
# via -r resources/requirements_mypy.in
types-urllib3==1.26.25.14
# via types-requests
Expand Down

0 comments on commit 591809d

Please sign in to comment.