Skip to content

Commit 6378a1c

Browse files
committed
small pass on annotations
1 parent fc99400 commit 6378a1c

13 files changed

Lines changed: 76 additions & 63 deletions

File tree

plotpy/items/curve/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,12 +360,12 @@ def get_data(self) -> tuple[np.ndarray, np.ndarray]:
360360
assert isinstance(self._x, np.ndarray) and isinstance(self._y, np.ndarray)
361361
return self._x, self._y
362362

363-
def update_data(self):
363+
def update_data(self) -> None:
364364
"""Update curve data with current arrays."""
365365
if isinstance(self._x, np.ndarray) and isinstance(self._y, np.ndarray):
366366
self._setData(self._x, self._y)
367367

368-
def _setData(self, x: np.ndarray, y: np.ndarray):
368+
def _setData(self, x: np.ndarray, y: np.ndarray) -> None:
369369
"""Wrapper around QwtPlotCurve.setData() to handle downsampling"""
370370
if not self.param.use_downsampling or self.param.downsampling_factor == 1:
371371
return super().setData(x, y)

plotpy/styles/curve.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class CurveParam(DataSet):
4949
"display", active=_downsampling_prop
5050
)
5151

52-
def update_param(self, curve: CurveItem | PolygonMapItem):
52+
def update_param(self, curve: CurveItem | PolygonMapItem) -> None:
5353
"""Updates the parameters using values from a given CurveItem/PolygonMapItem
5454
5555
Args:
@@ -61,7 +61,7 @@ def update_param(self, curve: CurveItem | PolygonMapItem):
6161
self.curvestyle = CURVESTYLE_NAME[curve.style()]
6262
self.baseline = curve.baseline()
6363

64-
def update_item(self, curve: CurveItem | PolygonMapItem):
64+
def update_item(self, curve: CurveItem | PolygonMapItem) -> None:
6565
"""Updates a given CurveItem/PolygonMapItem using the current parameters
6666
6767
Args:

plotpy/styles/image.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# -*- coding: utf-8 -*-
22

3+
from typing import Callable
4+
35
import numpy as np
46
from guidata.dataset import (
57
BeginGroup,
@@ -23,9 +25,9 @@
2325
from plotpy.styles.base import ItemParameters
2426

2527

26-
def _create_choices():
27-
choices = []
28-
for cmap_name in ALL_COLORMAPS.keys():
28+
def _create_choices() -> list[tuple[str, str, Callable[[str], QG.QIcon]]]:
29+
choices: list[tuple[str, str, Callable[[str], QG.QIcon]]] = []
30+
for cmap_name in ALL_COLORMAPS:
2931
choices.append((cmap_name, cmap_name, build_icon_from_cmap_name))
3032
return choices
3133

plotpy/tests/features/test_colormap_editor.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@
2323
from plotpy.widgets.colormap_widget import CustomQwtLinearColormap
2424

2525

26-
def test_colormap_manager():
26+
def test_colormap_manager() -> None:
27+
"""Test the colormap editor widget and the CustomQwtLinearColormap class
28+
by using multiple methods to initialize and export the colormap.
29+
"""
2730
with qt_app_context(exec_loop=True):
2831
print("Initialization of a default colormap editor widget")
2932
editor = ColorMapEditor(None)

plotpy/tests/features/test_colormap_manager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
from plotpy.widgets.colormap_widget import CustomQwtLinearColormap
2121

2222

23-
def test_colormap_manager():
23+
def test_colormap_manager() -> None:
24+
"""Test the colormap manager widget."""
2425
with qt_app_context(exec_loop=True):
25-
# app = QW.QApplication([])
2626
red = QG.QColor(QC.Qt.GlobalColor.red)
2727
blue = QG.QColor(QC.Qt.GlobalColor.blue)
2828
yellow = QG.QColor(QC.Qt.GlobalColor.yellow)

plotpy/tests/tools/test_downsample_curve.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
# guitest: show
1313

14+
from typing import Any
15+
1416
from guidata.qthelpers import exec_dialog, qt_app_context
1517
from numpy import linspace, sin
1618

@@ -19,7 +21,7 @@
1921
from plotpy.tools import DownSampleCurveTool, EditPointTool
2022

2123

22-
def callback_function(tool: EditPointTool):
24+
def callback_function(tool: EditPointTool) -> None:
2325
"""Callback that is called by the tool when the user stops clicking. Just prints
2426
the new arrays and the changes.
2527
@@ -31,9 +33,17 @@ def callback_function(tool: EditPointTool):
3133
print("Indexed changes:", tool.get_changes())
3234

3335

34-
def edit_downsampled_curve(downsampling_factor: int, *args):
36+
def edit_downsampled_curve(downsampling_factor: int, *args) -> tuple[Any, ...]:
3537
"""
3638
Plot curves and return selected point(s) coordinates
39+
40+
Args:
41+
downsampling_factor: downsampling factor (>=1)
42+
*args: arguments to be passed to the plotpy builder make.mcurve function
43+
44+
Returns:
45+
Modified *args input that can be used in another call to this function to check
46+
the interaction between edit tool and the donwsampling tool.
3747
"""
3848
win = make.dialog(
3949
wintitle=_("Select one point then press OK to accept"),
@@ -65,8 +75,8 @@ def edit_downsampled_curve(downsampling_factor: int, *args):
6575
return args
6676

6777

68-
def test_edit_curve():
69-
"""Test"""
78+
def test_downsample_curve() -> None:
79+
"""Test the downsample curve tool."""
7080
with qt_app_context(exec_loop=False):
7181
nlines = 1000
7282
x = linspace(-10, 10, num=nlines)
@@ -78,4 +88,4 @@ def test_edit_curve():
7888

7989

8090
if __name__ == "__main__":
81-
test_edit_curve()
91+
test_downsample_curve()

plotpy/tools/base.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# -*- coding: utf-8 -*-
2+
from __future__ import annotations
23

34
import weakref
45
from typing import Any, TypeVar

plotpy/tools/curve.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class CurveStatsTool(BaseCursorTool):
5353

5454
def __init__(
5555
self, manager, toolbar_id=DefaultToolbarID, title=None, icon=None, tip=None
56-
):
56+
) -> None:
5757
super().__init__(manager, toolbar_id, title=title, icon=icon, tip=tip)
5858
self._last_item = None
5959
self.label = None
@@ -340,7 +340,7 @@ def __init__(
340340
marker_style=None,
341341
switch_to_default_tool=None,
342342
max_select: int | None = None,
343-
):
343+
) -> None:
344344
super().__init__(
345345
manager,
346346
toolbar_id,
@@ -637,7 +637,7 @@ class InsertionDataSet(DataSet):
637637
index_offset = ChoiceItem(_("Location"), choices=["Before", "After"], default=0)
638638

639639
@classmethod
640-
def set_max_index(cls, max_index: int):
640+
def set_max_index(cls, max_index: int) -> None:
641641
"""Sets the maximum index value for the index field
642642
643643
Args:

plotpy/tools/image.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# -*- coding: utf-8 -*-
12
"""Image tools"""
23

34
from __future__ import annotations

plotpy/widgets/_colormap_slider.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# -*- coding: utf-8 -*-
2+
13
"""A custom QDoubleRangeSlider with some extra functionnalities for colormap sliders.
24
"""
35
from typing import Sequence
@@ -10,7 +12,7 @@ class QColorMapSlider(QDoubleRangeSlider):
1012
sliders."""
1113

1214
@property
13-
def pressed_index(self):
15+
def pressed_index(self) -> int:
1416
"""Simple getter for the index of the handle pressed by the user
1517
(mouse clicked).
1618

0 commit comments

Comments
 (0)