Skip to content

Commit f1342d8

Browse files
committed
final pylint pass
1 parent 5a6002d commit f1342d8

12 files changed

Lines changed: 70 additions & 34 deletions

File tree

.vscode/tasks.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@
127127
"run_pylint.bat",
128128
// "--disable=R0801,C0103,C0114,C0115,C0116,W0612,W0613",
129129
"--disable=fixme,C,R,W",
130+
"--ignore=external",
130131
],
131132
"options": {
132133
"cwd": "scripts",

plotpy/mathutils/colormaps.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
# -*- coding: utf-8 -*-
2+
"""This module provides utilities to interact with colormap. It provides functions
3+
to load/save colormaps from/to json files and to build icons representing the
4+
colormaps.
5+
"""
26
#
37
# Licensed under the terms of the BSD 3-Clause
48
# (see plotpy/LICENSE for details)
@@ -35,10 +39,10 @@ def load_raw_colormaps_from_json(
3539
Dictionnary of colormaps names -> raw colormap sequences
3640
"""
3741
if isinstance(json_path, str) and os.path.isfile(json_path):
38-
with open(json_path) as f:
42+
with open(json_path, encoding="utf-8") as f:
3943
try:
4044
return json.load(f)
41-
except BaseException as e:
45+
except json.JSONDecodeError as e:
4246
print(e)
4347
return {}
4448
return {}
@@ -71,7 +75,7 @@ def save_colormaps(json_filename: str, colormaps: dict[str, CustomQwtLinearColor
7175
"""
7276
raw_colormaps = {name: cmap.to_tuples() for name, cmap in colormaps.items()}
7377
json_abs_path = CONF.get_path(json_filename)
74-
with open(json_abs_path, "w") as f:
78+
with open(json_abs_path, "w", encoding="utf-8") as f:
7579
json.dump(raw_colormaps, f, indent=4)
7680

7781

@@ -139,7 +143,7 @@ def get_cmap_path(config_path: str):
139143
)
140144
if os.path.isfile(data_config_path):
141145
return data_config_path
142-
except BaseException as e:
146+
except (FileNotFoundError, PermissionError, OSError) as e:
143147
print(e)
144148

145149
user_config_path = CONF.get_path(config_path)
@@ -154,11 +158,17 @@ def get_cmap_path(config_path: str):
154158

155159
# Load default colormaps path from the config file
156160
DEFAULT_COLORMAPS_PATH = get_cmap_path(
157-
CONF.get("colormaps", "colormaps/default", default="colormaps_default.json") # type: ignore
161+
CONF.get(
162+
"colormaps",
163+
"colormaps/default",
164+
default="colormaps_default.json", # type: ignore
165+
)
158166
)
159167
# Load custom colormaps path from the config file
160168
CUSTOM_COLORMAPS_PATH = get_cmap_path(
161-
CONF.get("colormaps", "colormaps/custom", default="colormaps_custom.json") # type: ignore
169+
CONF.get(
170+
"colormaps", "colormaps/custom", default="colormaps_custom.json" # type: ignore
171+
)
162172
)
163173

164174
# Load default and custom colormaps from json files

plotpy/styles/curve.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030

3131

3232
class CurveParam(DataSet):
33+
"""Dataset defining the parameters of a CurveItem or PolygonMapItem"""
34+
3335
_multiselection = False
3436
label = StringItem(_("Title"), default="").set_prop(
3537
"display", hide=GetAttrProp("_multiselection")
@@ -91,6 +93,8 @@ def update_item(self, curve: CurveItem | PolygonMapItem):
9193

9294

9395
class CurveParam_MS(CurveParam):
96+
"""Same as CurveParam but for multiselection"""
97+
9498
_multiselection = True
9599

96100

plotpy/tests/features/test_colormap_editor.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import qtpy.QtCore as QC
1818
import qtpy.QtGui as QG
1919
import qtpy.QtWidgets as QW
20-
from guidata.env import execenv
2120

2221
from plotpy.widgets.colormap_editor import ColorMapEditor
2322
from plotpy.widgets.colormap_widget import CustomQwtLinearColormap

plotpy/tests/features/test_colormap_manager.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
import qtpy.QtCore as QC
1515
import qtpy.QtGui as QG
16-
import qtpy.QtWidgets as QW
1716
from guidata.qthelpers import qt_app_context
1817

1918
from plotpy.mathutils.colormaps import ALL_COLORMAPS

plotpy/tests/tools/test_downsample_curve.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@
2020

2121

2222
def callback_function(tool: EditPointTool):
23+
"""Callback that is called by the tool when the user stops clicking. Just prints
24+
the new arrays and the changes.
25+
26+
Args:
27+
tool: tool instance that can be used to retrieve the new arrays and the
28+
changes
29+
"""
2330
print("New arrays:", tool.get_arrays())
2431
print("Indexed changes:", tool.get_changes())
2532

plotpy/tools/curve.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# -*- coding: utf-8 -*-
2-
32
"""Curve tools"""
43

54
from __future__ import annotations
@@ -425,7 +424,7 @@ def _init_current_marker(
425424
"""
426425
plot = filter.plot
427426
if not isinstance(plot, BasePlot):
428-
return None
427+
return
429428
if force_new_marker or self.current_location_marker is None:
430429
title = title or f"<b>{self.TITLE} {len(self.markers)}</b><br>"
431430
constraint_cb = plot.on_active_curve if self.on_active_item else None
@@ -475,7 +474,7 @@ def move(self, filter: StatefulEventFilter, event: QG.QMouseEvent) -> None:
475474
"""
476475
plot = filter.plot
477476
if not isinstance(plot, BasePlot):
478-
return None
477+
return
479478
if self.current_location_marker is None:
480479
return # something is wrong ...
481480
self.current_location_marker.move_local_point_to(0, event.pos())
@@ -639,6 +638,11 @@ class InsertionDataSet(DataSet):
639638

640639
@classmethod
641640
def set_max_index(cls, max_index: int):
641+
"""Sets the maximum index value for the index field
642+
643+
Args:
644+
max_index: max index value
645+
"""
642646
cls.index.set_prop("data", max=max_index)
643647

644648
def __init__(
@@ -1038,11 +1042,11 @@ def get_changes(self) -> dict[CurveItem, dict[int, tuple[float, float]]]:
10381042
"""Get changes"""
10391043
return self._indexed_changes
10401044

1041-
def get_arrays(self) -> tuple[np.ndarray| None, np.ndarray | None]:
1045+
def get_arrays(self) -> tuple[np.ndarray | None, np.ndarray | None]:
10421046
"""Get arrays"""
10431047
return self._x, self._y
10441048

1045-
def get_initial_arrays(self) -> tuple[np.ndarray| None, np.ndarray | None]:
1049+
def get_initial_arrays(self) -> tuple[np.ndarray | None, np.ndarray | None]:
10461050
"""Get initial arrays"""
10471051
return self._x_bkp, self._y_bkp
10481052

plotpy/tools/image.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Image tools"""
2+
13
from __future__ import annotations
24

35
import weakref
@@ -113,10 +115,10 @@ def get_infos(self) -> str | None:
113115
str: Formatted string with informations on current shape
114116
"""
115117
if self.image_item is None:
116-
return
118+
return None
117119
plot = self.image_item.plot()
118120
if plot is None:
119-
return
121+
return None
120122
p0y = plot.transform(0, self.shape.get_points()[0][1])
121123
p0x = plot.transform(2, self.shape.get_points()[0][0])
122124
p1y = plot.transform(0, self.shape.get_points()[1][1])
@@ -198,6 +200,7 @@ def get_last_item(self) -> BaseImageItem | None:
198200
"""
199201
if self._last_item is not None:
200202
return self._last_item()
203+
return None
201204

202205
def create_shape(self):
203206
"""Returns a new ImageStatsRectangle instance with default x1, y1, x2, y2values
@@ -509,7 +512,7 @@ def get_selected_images(self, plot: BasePlot):
509512
Returns:
510513
list of currently selected images in the given plot
511514
"""
512-
items = [it for it in plot.get_selected_items(item_type=IColormapImageItemType)]
515+
items = plot.get_selected_items(item_type=IColormapImageItemType)
513516
if not items:
514517
active_image = plot.get_last_active_item(IColormapImageItemType)
515518
if active_image:
@@ -758,10 +761,10 @@ def find_masked_image(
758761
item = plot.get_active_item()
759762
if isinstance(item, maskedtypes):
760763
return item
761-
else:
762-
items = [item for item in plot.get_items() if isinstance(item, maskedtypes)]
763-
if items:
764-
return items[-1]
764+
items = [item for item in plot.get_items() if isinstance(item, maskedtypes)]
765+
if items:
766+
return items[-1]
767+
return None
765768

766769
def create_shapes_from_masked_areas(self):
767770
"""Creates shapes from the masked areas of the masked image (rectangular or
@@ -1118,7 +1121,7 @@ def update_status(self, plot: BasePlot):
11181121
plot: Plot instance
11191122
"""
11201123
status = any(
1121-
[isinstance(item, TrImageItem) for item in plot.get_selected_items()]
1124+
isinstance(item, TrImageItem) for item in plot.get_selected_items()
11221125
)
11231126
self.action.setEnabled(status)
11241127

plotpy/widgets/_colormap_slider.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1+
"""A custom QDoubleRangeSlider with some extra functionnalities for colormap sliders.
2+
"""
13
from typing import Sequence
24

3-
import qtpy.QtCore as QC
4-
import qtpy.QtGui as QG
5-
import qtpy.QtWidgets as QW
6-
75
from plotpy.external.sliders import QDoubleRangeSlider
86

97

108
class QColorMapSlider(QDoubleRangeSlider):
11-
"""supercharged QDoubleRangeSlider with a few extra features for colormap
9+
"""Supercharged QDoubleRangeSlider with a few extra features for colormap
1210
sliders."""
1311

1412
@property
@@ -46,14 +44,14 @@ def filter_first_last_positions(self, value: Sequence[float]) -> Sequence[float]
4644
value[0], value[-1] = self._minimum, self._maximum
4745
return value
4846

49-
def _setPosition(self, value: Sequence[float]) -> None:
47+
def _setPosition(self, val: Sequence[float]) -> None:
5048
"""Overload of the original _setPosition method to prevent the application from
5149
crashing if the first and last handles are moved.
5250
5351
Args:
5452
value: list of handle values
5553
"""
56-
return super()._setPosition(self.filter_first_last_positions(value))
54+
return super()._setPosition(self.filter_first_last_positions(val))
5755

5856
def setValue(self, value: Sequence[float]) -> None:
5957
"""Overload of the original setValue method to prevent the application from

plotpy/widgets/colormap_editor.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
# Licensed under the terms of the BSD 3-Clause
44
# (see plotpy/LICENSE for details)
55

6+
"""This module provides a more complete colormap editor widget than the one provided
7+
by ColorMapWidget (plotpy/widgets/colormap_widget.py). It allows to edit a colormap
8+
by changing its color stops (add/delete/move/change color).
9+
"""
10+
611
import qtpy.QtCore as QC
712
import qtpy.QtGui as QG
813
import qtpy.QtWidgets as QW
@@ -267,7 +272,7 @@ def update_colormap_widget(self):
267272

268273
new_slider_values = self.colormap_widget.get_handles_list()
269274

270-
if current_index > 0 and current_index < self.tabs.count() - 1:
275+
if 0 < current_index < self.tabs.count() - 1:
271276
relative_pos = current_dataset.get_position()
272277
else:
273278
relative_pos = new_slider_values[current_index]

0 commit comments

Comments
 (0)