Skip to content

Commit 505604f

Browse files
committed
Fix some pylint warnings (except remaining cyclic imports)
1 parent a1cdcad commit 505604f

File tree

5 files changed

+34
-20
lines changed

5 files changed

+34
-20
lines changed

cdl/tests/sigima_tests/image_io_formats_test.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,26 @@
44
Image I/O formats test
55
"""
66

7+
# Note about the modules imported outside top-level:
8+
#
9+
# We want to keep the import order under control, so we import the modules only when
10+
# they are needed, especially for the dynamically defined image formats in the `formats`
11+
# module. This way, we can ensure that the formats are defined just before we use them
12+
# in the tests. This is particularly useful for testing the `imageio_formats` option
13+
# that allows users to set custom image I/O formats.
14+
715

816
def get_image_formats():
917
"""Get image formats"""
18+
# pylint: disable=import-outside-toplevel
1019
from sigima_.io.image import formats
1120

12-
return [
13-
class_name for class_name in dir(formats) if class_name.endswith("ImageFormat")
14-
]
21+
return [clname for clname in dir(formats) if clname.endswith("ImageFormat")]
1522

1623

1724
def test_imageio_formats_option():
1825
"""Set other image I/O formats"""
26+
# pylint: disable=import-outside-toplevel
1927
from sigima_.config import options
2028
from sigima_.io.image import formats
2129

cdl/tests/sigima_tests/images/operation_unit_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ def test_image_product() -> None:
152152

153153

154154
@pytest.mark.validation
155-
def test_image_division(request: pytest.FixtureRequest) -> None:
155+
def test_image_division(request: pytest.FixtureRequest = None) -> None:
156156
"""Image division test."""
157157
execenv.print("*** Testing image division:")
158158
for ima1, ima2 in __iterate_image_couples():

sigima_/computation/base.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,13 @@ def dst_n_to_1(
264264
return dst
265265

266266

267+
# Note about `src2` parameter:
268+
# ----------------------------
269+
# The `src2` parameter is currently not used in the function, but it is included
270+
# to maintain a consistent interface with other similar functions (e.g., `dst_n_to_1`).
271+
# This may be useful in the future if we want to extend the functionality.
272+
#
273+
# pylint: disable=unused-argument
267274
def dst_2_to_1(
268275
src1: SignalObj | ImageObj,
269276
src2: SignalObj | ImageObj,

sigima_/config.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,14 @@ def check(self, value: Any) -> None: # pylint: disable=unused-argument
9090
ValueError: If the value is not valid.
9191
"""
9292
# This method can be overridden in subclasses for specific validation
93-
pass
9493

9594
def get(self) -> Any:
9695
"""Return the current value of the option.
9796
9897
Returns:
9998
The current value of the option.
10099
"""
101-
self._container._ensure_loaded_from_env()
100+
self._container.ensure_loaded_from_env()
102101
return self._value
103102

104103
def set(self, value: Any, sync_env: bool = True) -> None:
@@ -111,7 +110,7 @@ def set(self, value: Any, sync_env: bool = True) -> None:
111110
self.check(value) # Validate the new value
112111
self._value = value
113112
if sync_env:
114-
self._container._sync_env()
113+
self._container.sync_env()
115114

116115
def context(self, temp_value: Any) -> Generator[None, None, None]:
117116
"""Temporarily override the option within a context.
@@ -218,13 +217,14 @@ def check(self, value: Any) -> None:
218217
"Each item must be a tuple of (format, description) as strings"
219218
)
220219

221-
def set(self, value: Any) -> None:
222-
"""Set the value of the image I/O formats option.
220+
def set(self, value: Any, sync_env: bool = True) -> None:
221+
"""Set the value of the option.
223222
224223
Args:
225224
value: The new value to assign.
225+
sync_env: Whether to synchronize the environment variable.
226226
"""
227-
super().set(value)
227+
super().set(value, sync_env)
228228
from sigima_.io.image import formats # pylint: disable=import-outside-toplevel
229229

230230
# Generate image I/O format classes based on the new value
@@ -285,9 +285,9 @@ def __init__(self) -> None:
285285
286286
.. note::
287287
288-
The `sigima` library supports any image format that can be read by the
289-
`imageio` library, provided that the associated plugin(s) are installed
290-
(see `imageio documentation <https://imageio.readthedocs.io/en/stable/formats/index.html>`_)
288+
The `sigima` library supports any image format that can be read by the `imageio`
289+
library, provided that the associated plugin(s) are installed (see `imageio
290+
documentation <https://imageio.readthedocs.io/en/stable/formats/index.html>`_)
291291
and that the output NumPy array data type and shape are supported by `sigima`.
292292
293293
To add a new file format, you may use the `imageio_formats` option to specify
@@ -330,19 +330,20 @@ def generate_rst_doc(self) -> str:
330330
doc += f" - {opt.description}\n"
331331
return doc
332332

333-
def _ensure_loaded_from_env(self) -> None:
333+
def ensure_loaded_from_env(self) -> None:
334334
"""Lazy-load from JSON env var on first access."""
335335
if self._loaded_from_env:
336336
return
337337
if self.ENV_VAR in os.environ:
338338
try:
339339
values = json.loads(os.environ[self.ENV_VAR])
340340
self.from_dict(values)
341-
except Exception as e:
342-
print(f"[sigima] Warning: failed to load options from env: {e}")
341+
except Exception as exc: # pylint: disable=broad-except
342+
# If loading fails, we just log a warning and continue with defaults
343+
print(f"[sigima] Warning: failed to load options from env: {exc}")
343344
self._loaded_from_env = True
344345

345-
def _sync_env(self) -> None:
346+
def sync_env(self) -> None:
346347
"""Update env var with current option values."""
347348
os.environ[self.ENV_VAR] = json.dumps(self.to_dict())
348349

@@ -369,7 +370,7 @@ def from_dict(self, values: dict[str, Any]) -> None:
369370
opt = getattr(self, name)
370371
if isinstance(opt, OptionField):
371372
opt.set(value, sync_env=False)
372-
self._sync_env()
373+
self.sync_env()
373374

374375

375376
#: Global instance of the options container

sigima_/worker.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,9 @@ class CallbackWorkerProtocol(Protocol):
3636

3737
def set_progress(self, value: float) -> None:
3838
"""Update progress (between 0.0 and 1.0)."""
39-
...
4039

4140
def was_canceled(self) -> bool:
4241
"""Check whether the operation has been canceled."""
43-
...
4442

4543

4644
class TextCallbackWorker:

0 commit comments

Comments
 (0)