Skip to content

Commit 58223ca

Browse files
authored
Merge pull request #104 from dstansby/nptyping
Add numpy and matplotlib to typing checks
2 parents d79873f + 3364bc3 commit 58223ca

File tree

4 files changed

+11
-8
lines changed

4 files changed

+11
-8
lines changed

.pre-commit-config.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ repos:
2525
rev: v1.2.0
2626
hooks:
2727
- id: mypy
28+
additional_dependencies: [numpy, matplotlib]
2829

2930
- repo: https://github.com/charliermarsh/ruff-pre-commit
3031
# Ruff version.

src/napari_matplotlib/scatter.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
from typing import List, Optional, Tuple
1+
from typing import Any, List, Optional, Tuple
22

33
import matplotlib.colors as mcolor
44
import napari
5-
import numpy as np
5+
import numpy.typing as npt
66
from magicgui import magicgui
77
from magicgui.widgets import ComboBox
88

@@ -65,7 +65,7 @@ def draw(self) -> None:
6565
self.axes.set_xlabel(x_axis_name)
6666
self.axes.set_ylabel(y_axis_name)
6767

68-
def _get_data(self) -> Tuple[List[np.ndarray], str, str]:
68+
def _get_data(self) -> Tuple[List[npt.NDArray[Any]], str, str]:
6969
"""Get the plot data.
7070
7171
This must be implemented on the subclass.
@@ -93,7 +93,7 @@ class ScatterWidget(ScatterBaseWidget):
9393
n_layers_input = Interval(2, 2)
9494
input_layer_types = (napari.layers.Image,)
9595

96-
def _get_data(self) -> Tuple[List[np.ndarray], str, str]:
96+
def _get_data(self) -> Tuple[List[npt.NDArray[Any]], str, str]:
9797
"""
9898
Get the plot data.
9999
@@ -191,7 +191,7 @@ def _get_valid_axis_keys(
191191
else:
192192
return self.layers[0].features.keys()
193193

194-
def _get_data(self) -> Tuple[List[np.ndarray], str, str]:
194+
def _get_data(self) -> Tuple[List[npt.NDArray[Any]], str, str]:
195195
"""
196196
Get the plot data.
197197

src/napari_matplotlib/slice.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
from typing import Dict, Tuple
1+
from typing import Any, Dict, Tuple
22

33
import napari
44
import numpy as np
5+
import numpy.typing as npt
56
from qtpy.QtWidgets import QComboBox, QHBoxLayout, QLabel, QSpinBox
67

78
from .base import NapariMPLWidget
@@ -87,7 +88,7 @@ def update_slice_selectors(self) -> None:
8788
for i, dim in enumerate(_dims_sel):
8889
self.slice_selectors[dim].setRange(0, self.layer.data.shape[i])
8990

90-
def get_xy(self) -> Tuple[np.ndarray, np.ndarray]:
91+
def get_xy(self) -> Tuple[npt.NDArray[Any], npt.NDArray[Any]]:
9192
"""
9293
Get data for plotting.
9394
"""

src/napari_matplotlib/tests/test_scatter.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from typing import Any, Dict, Tuple
22

33
import numpy as np
4+
import numpy.typing as npt
45

56
from napari_matplotlib import FeaturesScatterWidget, ScatterWidget
67

@@ -22,7 +23,7 @@ def test_features_scatter_widget(make_napari_viewer):
2223

2324

2425
def make_labels_layer_with_features() -> (
25-
Tuple[np.ndarray, Dict[str, Tuple[Any]]]
26+
Tuple[npt.NDArray[np.uint16], Dict[str, Any]]
2627
):
2728
label_image = np.zeros((100, 100), dtype=np.uint16)
2829
for label_value, start_index in enumerate([10, 30, 50], start=1):

0 commit comments

Comments
 (0)