Skip to content

Commit 7068812

Browse files
committed
linters are happy, and .zgroup file writing is more robust
1 parent d046f3c commit 7068812

10 files changed

+526
-216
lines changed

illumifix/__init__.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
11
"""Project root"""
22

3+
import json
34
from pathlib import Path
4-
from ome_zarr.format import FormatV02
55

6-
# Make the __version__ attribute of the project available at the top level.
7-
from ._version import __version__
6+
from ome_zarr.format import FormatV02 # type: ignore[import-untyped]
87

8+
# Make the __version__ attribute of the project available at the top level.
9+
from ._version import __version__ # noqa: F401
910

1011
PROJECT_NAME = Path(__file__).resolve().parent.name
1112

13+
14+
class JsonEncoderForZarrFormat(json.JSONEncoder):
15+
"""Allow encoding of a zarr.Format value as JSON."""
16+
17+
def default(self, o) -> object: # type: ignore[no-untyped-def] # noqa: ANN001
18+
"""Attempt to encode the given object as JSON."""
19+
match o:
20+
case FormatV02():
21+
return {"zarr_format": 2}
22+
case _:
23+
return super().default(o)
24+
25+
1226
ZARR_FORMAT = FormatV02()

illumifix/expression_utilities.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,19 @@
1111

1212

1313
def separate(results: Iterable[Result[_TSource, _TError]]) -> tuple[list[_TError], list[_TSource]]:
14+
"""Separate the given collection into errors and Oks.
15+
16+
Args:
17+
results (Iterable[Result[_TSource, _TError]]): the collection of wrapped values to split into errors and Oks.
18+
19+
Raises:
20+
TypeError: if any element in the given collection isn't a result.Result
21+
22+
Returns:
23+
tuple[list[_TError], list[_TSource]]: a pair of lists,
24+
the first of which is the errors and the second of which is the Oks
25+
26+
"""
1427
bads: list[_TError] = []
1528
goods: list[_TSource] = []
1629
for i, res in enumerate(results):
@@ -29,6 +42,16 @@ def separate(results: Iterable[Result[_TSource, _TError]]) -> tuple[list[_TError
2942
def sequence_accumulate_errors(
3043
results: Iterable[Result[_TSource, _TError]],
3144
) -> Result[list[_TSource], list[_TError]]:
45+
"""Return a result.Error wrapping all such values if any exists, otherwise a result.Ok wrapping all Ok-wrapped values
46+
47+
Args:
48+
results (Iterable[Result[_TSource, _TError]]): the collection of values to process
49+
50+
Returns:
51+
Result[list[_TSource], list[_TError]]: a result.Ok wrapping all values if every one is a result.Ok,
52+
otherwise a result.Error wrapping a list of all result.Error-wrapped values
53+
54+
"""
3255
bads, goods = separate(results)
3356
return Result.Error(bads) if bads else Result.Ok(goods)
3457

@@ -38,4 +61,15 @@ def traverse_accumulate_errors(
3861
inputs: Iterable[_TInput],
3962
func: Callable[[_TInput], Result[_TSource, _TError]],
4063
) -> Result[list[_TSource], list[_TError]]:
64+
"""Apply the given function to each element, returning a result.Ok-wrapped collection of resulting values if every application succeeds, otherwise a result.Error wrapping all error values.
65+
66+
Args:
67+
inputs (Iterable[_TInput]): the elements to input to the given function
68+
func (Callable[[_TInput], Result[_TSource, _TError]]): the function to apply to each element
69+
70+
Returns:
71+
Result[list[_TSource], list[_TError]]: either a result.Ok-wrapped collection of resulting values
72+
of every application succeeds, otherwise a result.Error wrapping all error values
73+
74+
"""
4175
return sequence_accumulate_errors(map(func, inputs))

0 commit comments

Comments
 (0)