Skip to content

Commit d768a92

Browse files
committed
Typing upgrades
1 parent 09f4e91 commit d768a92

File tree

7 files changed

+24
-24
lines changed

7 files changed

+24
-24
lines changed

src/napari_matplotlib/base.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import os
22
from pathlib import Path
3-
from typing import List, Optional, Tuple
3+
from typing import Optional
44

55
import matplotlib
66
import matplotlib.style as mplstyle
@@ -184,7 +184,7 @@ class NapariMPLWidget(BaseNapariMPLWidget):
184184
#: Number of layers taken as input
185185
n_layers_input = Interval(None, None)
186186
#: Type of layer taken as input
187-
input_layer_types: Tuple[napari.layers.Layer, ...] = (napari.layers.Layer,)
187+
input_layer_types: tuple[napari.layers.Layer, ...] = (napari.layers.Layer,)
188188

189189
def __init__(
190190
self,
@@ -193,7 +193,7 @@ def __init__(
193193
):
194194
super().__init__(napari_viewer=napari_viewer, parent=parent)
195195
self._setup_callbacks()
196-
self.layers: List[napari.layers.Layer] = []
196+
self.layers: list[napari.layers.Layer] = []
197197

198198
helper_text = self.n_layers_input._helper_text
199199
if helper_text is not None:

src/napari_matplotlib/histogram.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, List, Optional, Tuple
1+
from typing import Any, Optional
22

33
import napari
44
import numpy as np
@@ -107,7 +107,7 @@ def _set_axis_keys(self, x_axis_key: str) -> None:
107107
self._x_axis_key = x_axis_key
108108
self._draw()
109109

110-
def _get_valid_axis_keys(self) -> List[str]:
110+
def _get_valid_axis_keys(self) -> list[str]:
111111
"""
112112
Get the valid axis keys from the layer FeatureTable.
113113
@@ -122,7 +122,7 @@ def _get_valid_axis_keys(self) -> List[str]:
122122
else:
123123
return self.layers[0].features.keys()
124124

125-
def _get_data(self) -> Tuple[Optional[npt.NDArray[Any]], str]:
125+
def _get_data(self) -> tuple[Optional[npt.NDArray[Any]], str]:
126126
"""Get the plot data.
127127
128128
Returns

src/napari_matplotlib/scatter.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, Dict, List, Optional, Tuple, Union
1+
from typing import Any, Optional, Union
22

33
import napari
44
import numpy.typing as npt
@@ -40,7 +40,7 @@ def draw(self) -> None:
4040
self.axes.set_xlabel(x_axis_name)
4141
self.axes.set_ylabel(y_axis_name)
4242

43-
def _get_data(self) -> Tuple[npt.NDArray[Any], npt.NDArray[Any], str, str]:
43+
def _get_data(self) -> tuple[npt.NDArray[Any], npt.NDArray[Any], str, str]:
4444
"""
4545
Get the plot data.
4646
@@ -67,7 +67,7 @@ class ScatterWidget(ScatterBaseWidget):
6767
n_layers_input = Interval(2, 2)
6868
input_layer_types = (napari.layers.Image,)
6969

70-
def _get_data(self) -> Tuple[npt.NDArray[Any], npt.NDArray[Any], str, str]:
70+
def _get_data(self) -> tuple[npt.NDArray[Any], npt.NDArray[Any], str, str]:
7171
"""
7272
Get the plot data.
7373
@@ -106,7 +106,7 @@ def __init__(
106106

107107
self.layout().addLayout(QVBoxLayout())
108108

109-
self._selectors: Dict[str, QComboBox] = {}
109+
self._selectors: dict[str, QComboBox] = {}
110110
for dim in ["x", "y"]:
111111
self._selectors[dim] = QComboBox()
112112
# Re-draw when combo boxes are updated
@@ -147,7 +147,7 @@ def y_axis_key(self, key: str) -> None:
147147
self._selectors["y"].setCurrentText(key)
148148
self._draw()
149149

150-
def _get_valid_axis_keys(self) -> List[str]:
150+
def _get_valid_axis_keys(self) -> list[str]:
151151
"""
152152
Get the valid axis keys from the layer FeatureTable.
153153
@@ -186,7 +186,7 @@ def draw(self) -> None:
186186
if self._ready_to_scatter():
187187
super().draw()
188188

189-
def _get_data(self) -> Tuple[npt.NDArray[Any], npt.NDArray[Any], str, str]:
189+
def _get_data(self) -> tuple[npt.NDArray[Any], npt.NDArray[Any], str, str]:
190190
"""
191191
Get the plot data from the ``features`` attribute of the first
192192
selected layer.

src/napari_matplotlib/slice.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, List, Optional, Tuple
1+
from typing import Any, Optional
22

33
import matplotlib.ticker as mticker
44
import napari
@@ -99,7 +99,7 @@ def current_dim_index(self) -> int:
9999
return self._dim_names.index(self.current_dim_name)
100100

101101
@property
102-
def _dim_names(self) -> List[str]:
102+
def _dim_names(self) -> list[str]:
103103
"""
104104
List of dimension names. This is a property as it varies depending on the
105105
dimensionality of the currently selected data.
@@ -111,7 +111,7 @@ def _dim_names(self) -> List[str]:
111111
else:
112112
raise RuntimeError("Don't know how to handle ndim != 2 or 3")
113113

114-
def _get_xy(self) -> Tuple[npt.NDArray[Any], npt.NDArray[Any]]:
114+
def _get_xy(self) -> tuple[npt.NDArray[Any], npt.NDArray[Any]]:
115115
"""
116116
Get data for plotting.
117117
"""

src/napari_matplotlib/tests/scatter/test_scatter_features.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from copy import deepcopy
2-
from typing import Any, Dict, Tuple
2+
from typing import Any
33

44
import numpy as np
55
import numpy.typing as npt
@@ -34,7 +34,7 @@ def test_features_scatter_widget_2D(
3434

3535

3636
def make_labels_layer_with_features() -> (
37-
Tuple[npt.NDArray[np.uint16], Dict[str, Any]]
37+
tuple[npt.NDArray[np.uint16], dict[str, Any]]
3838
):
3939
label_image: npt.NDArray[np.uint16] = np.zeros((100, 100), dtype=np.uint16)
4040
for label_value, start_index in enumerate([10, 30, 50], start=1):

src/napari_matplotlib/tests/test_layer_changes.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from copy import deepcopy
2-
from typing import Any, Dict, Tuple, Type
2+
from typing import Any
33

44
import numpy as np
55
import numpy.typing as npt
@@ -61,8 +61,8 @@ def test_change_features_layer(
6161

6262
def assert_features_plot_changes(
6363
viewer: Viewer,
64-
widget_cls: Type[NapariMPLWidget],
65-
data: Tuple[npt.NDArray[np.generic], Dict[str, Any]],
64+
widget_cls: type[NapariMPLWidget],
65+
data: tuple[npt.NDArray[np.generic], dict[str, Any]],
6666
) -> None:
6767
"""
6868
When the selected layer is changed, make sure the plot generated

src/napari_matplotlib/util.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import List, Optional, Tuple, Union
1+
from typing import Optional, Union
22
from warnings import warn
33

44
import napari.qt
@@ -76,7 +76,7 @@ def _helper_text(self) -> Optional[str]:
7676
return helper_text
7777

7878

79-
def _has_id(nodes: List[tinycss2.ast.Node], id_name: str) -> bool:
79+
def _has_id(nodes: list[tinycss2.ast.Node], id_name: str) -> bool:
8080
"""
8181
Is `id_name` in IdentTokens in the list of CSS `nodes`?
8282
"""
@@ -86,7 +86,7 @@ def _has_id(nodes: List[tinycss2.ast.Node], id_name: str) -> bool:
8686

8787

8888
def _get_dimension(
89-
nodes: List[tinycss2.ast.Node], id_name: str
89+
nodes: list[tinycss2.ast.Node], id_name: str
9090
) -> Union[int, None]:
9191
"""
9292
Get the value of the DimensionToken for the IdentToken `id_name`.
@@ -108,7 +108,7 @@ def _get_dimension(
108108

109109

110110
def from_napari_css_get_size_of(
111-
qt_element_name: str, fallback: Tuple[int, int]
111+
qt_element_name: str, fallback: tuple[int, int]
112112
) -> QSize:
113113
"""
114114
Get the size of `qt_element_name` from napari's current stylesheet.

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