Skip to content

Commit ad86290

Browse files
committed
Make mypy more strict
1 parent 7d59cd6 commit ad86290

File tree

6 files changed

+31
-8
lines changed

6 files changed

+31
-8
lines changed

pyproject.toml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,24 @@ select = ["I", "UP", "F", "E", "W"]
1919
fix = true
2020

2121
[tool.mypy]
22+
# Block below are checks that form part of mypy 'strict' mode
23+
warn_unused_configs = true
24+
warn_redundant_casts = true
25+
warn_unused_ignores = true
26+
strict_equality = true
27+
strict_concatenate = true
28+
check_untyped_defs = true
29+
disallow_subclassing_any = false # TODO: fix
30+
disallow_untyped_decorators = true
31+
disallow_any_generics = true
32+
disallow_untyped_calls = true
2233
disallow_incomplete_defs = true
23-
ignore_missing_imports = true
34+
disallow_untyped_defs = true
35+
no_implicit_reexport = true
36+
warn_return_any = false # TODO: fix
37+
38+
[[tool.mypy.overrides]]
39+
module = [
40+
"napari_matplotlib/tests/*",
41+
]
42+
disallow_untyped_defs = false

src/napari_matplotlib/base.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def draw(self) -> None:
125125
This is a no-op, and is intended for derived classes to override.
126126
"""
127127

128-
def apply_napari_colorscheme(self):
128+
def apply_napari_colorscheme(self) -> None:
129129
"""
130130
Apply napari-compatible colorscheme to the axes object.
131131
"""
@@ -157,7 +157,7 @@ def _on_update_layers(self) -> None:
157157
This is a no-op, and is intended for derived classes to override.
158158
"""
159159

160-
def _replace_toolbar_icons(self):
160+
def _replace_toolbar_icons(self) -> None:
161161
# Modify toolbar icons and some tooltips
162162
for action in self.toolbar.actions():
163163
text = action.text()
@@ -179,7 +179,7 @@ def _replace_toolbar_icons(self):
179179
class NapariNavigationToolbar(NavigationToolbar2QT):
180180
"""Custom Toolbar style for Napari."""
181181

182-
def _update_buttons_checked(self):
182+
def _update_buttons_checked(self) -> None:
183183
"""Update toggle tool icons when selected/unselected."""
184184
super()._update_buttons_checked()
185185
# changes pan/zoom icons depending on state (checked or not)

src/napari_matplotlib/slice.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def __init__(self, napari_viewer: napari.viewer.Viewer):
4949
self.update_layers(None)
5050

5151
@property
52-
def layer(self):
52+
def layer(self) -> napari.Layer:
5353
return self.layers[0]
5454

5555
@property

src/napari_matplotlib/tests/test_scatter.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import Any, Dict, Tuple
2+
13
import numpy as np
24

35
from napari_matplotlib import FeaturesScatterWidget, ScatterWidget
@@ -19,7 +21,9 @@ def test_features_scatter_widget(make_napari_viewer):
1921
FeaturesScatterWidget(viewer)
2022

2123

22-
def make_labels_layer_with_features():
24+
def make_labels_layer_with_features() -> (
25+
Tuple[np.ndarray, Dict[str, Tuple[Any]]]
26+
):
2327
label_image = np.zeros((100, 100), dtype=np.uint16)
2428
for label_value, start_index in enumerate([10, 30, 50], start=1):
2529
end_index = start_index + 10

src/napari_matplotlib/tests/test_util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ def test_interval():
1212
assert 10 not in interval
1313

1414
with pytest.raises(ValueError, match="must be an integer"):
15-
"string" in interval
15+
"string" in interval # type: ignore

src/napari_matplotlib/util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def __init__(self, lower_bound: Optional[int], upper_bound: Optional[int]):
1919
self.lower = lower_bound
2020
self.upper = upper_bound
2121

22-
def __contains__(self, val):
22+
def __contains__(self, val: int) -> bool:
2323
if not isinstance(val, int):
2424
raise ValueError("variable must be an integer")
2525
if self.lower is not None and val < self.lower:

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy