Skip to content

Commit f768344

Browse files
authored
fix: remove type ignore comments for improved type checking (#44)
1 parent f51a54b commit f768344

11 files changed

Lines changed: 37 additions & 33 deletions

File tree

examples/demo_from_uri.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from yaozarrs import validate_ome_uri
1616

1717
try:
18-
from rich import print # ty: ignore
18+
from rich import print
1919
except ImportError:
2020
print = builtins.print # type: ignore # noqa
2121

scripts/fetch.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from pathlib import Path, PurePosixPath
88
from typing import Any
99

10-
import fsspec # type: ignore
10+
import fsspec
1111

1212
META_SUFFIXES = (
1313
"zarr.json", # Zarr v3
@@ -115,7 +115,7 @@ def metadata_mirror(remote_url: str, local_parent: str, verbose: bool = True) ->
115115
str
116116
Path to the local mirrored store directory.
117117
"""
118-
fs, root = fsspec.url_to_fs(remote_url) # type: ignore
118+
fs, root = fsspec.url_to_fs(remote_url)
119119

120120
root_path = PurePosixPath(root.rstrip("/"))
121121
root_name = root_path.name or root_path.parent.name

src/yaozarrs/_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class _BaseModel(BaseModel):
2222
validate_assignment=True,
2323
validate_default=True,
2424
serialize_by_alias=True,
25-
**_by_name_cfg, # type: ignore[typeddict-item]
25+
**_by_name_cfg,
2626
)
2727

2828
if not TYPE_CHECKING:

src/yaozarrs/_demo_data.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,13 @@ def write_ome_image(
131131
win_max = 1.0
132132

133133
for i in range(n_channels):
134-
channel = {"window": {"start": 0, "min": 0, "end": win_max, "max": win_max}}
134+
channel: dict[str, Any] = {
135+
"window": {"start": 0, "min": 0, "end": win_max, "max": win_max}
136+
}
135137
if channel_names and i < len(channel_names):
136-
channel["label"] = channel_names[i] # pyright: ignore
138+
channel["label"] = channel_names[i]
137139
if channel_colors and i < len(channel_colors):
138-
channel["color"] = f"{channel_colors[i]:06x}" # pyright: ignore
140+
channel["color"] = f"{channel_colors[i]:06x}"
139141
channels.append(channel)
140142

141143
metadata_kwargs["metadata"] = {"omero": {"channels": channels}}
@@ -377,12 +379,14 @@ def write_ome_plate(
377379
field_paths: list[str | dict] = [str(i) for i in range(fields_per_well)]
378380

379381
# Write well metadata
380-
well_metadata: dict = {"images": [{"path": path} for path in field_paths]}
382+
well_metadata: dict[str, Any] = {
383+
"images": [{"path": path} for path in field_paths]
384+
}
381385

382386
if acquisitions:
383387
# Add acquisition references to images
384388
for i, img in enumerate(well_metadata["images"]):
385-
img["acquisition"] = i % len(acquisitions)
389+
img["acquisition"] = i % len(acquisitions) # ty: ignore[invalid-assignment]
386390

387391
writer.write_well_metadata(well_group, field_paths)
388392

src/yaozarrs/_storage.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def _custom_formatwarning(message, category, *_, **__) -> str:
9494
# Format like an exception: module.Class: message
9595
return f"{category.__module__}.{category.__name__}: {message}\n"
9696

97-
warnings.formatwarning = _custom_formatwarning # type: ignore
97+
warnings.formatwarning = _custom_formatwarning # ty: ignore[invalid-assignment]
9898
try:
9999
warnings.warn(warning_instance, stacklevel=2)
100100
finally:

src/yaozarrs/_zarr.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@
4646
from typing import TypeVar
4747

4848
import rich.tree
49-
import tensorstore # type: ignore
50-
import zarr # type: ignore
49+
import tensorstore
50+
import zarr
5151
from fsspec import FSMap
5252
from typing_extensions import Self
5353

@@ -509,7 +509,7 @@ def to_zarr_python(self) -> zarr.Array | zarr.Group:
509509
Requires `zarr-python` to be installed.
510510
"""
511511
try:
512-
import zarr # type: ignore
512+
import zarr
513513
except ImportError as e:
514514
raise ImportError("zarr package is required for to_zarr_python()") from e
515515

@@ -815,7 +815,7 @@ def _getitem_v2(self, child_path: str, key: str) -> ZarrGroup | ZarrArray:
815815

816816
if TYPE_CHECKING:
817817

818-
def to_zarr_python(self) -> zarr.Group: # type: ignore
818+
def to_zarr_python(self) -> zarr.Group:
819819
"""Convert to a zarr-python Group object.
820820
821821
!!!important
@@ -856,7 +856,7 @@ def dtype(self) -> str:
856856

857857
if TYPE_CHECKING:
858858

859-
def to_zarr_python(self) -> zarr.Array: # type: ignore
859+
def to_zarr_python(self) -> zarr.Array:
860860
"""Convert to a zarr-python Array object.
861861
862862
!!!important
@@ -870,7 +870,7 @@ def to_tensorstore(self) -> tensorstore.TensorStore:
870870
Requires `tensorstore` to be installed.
871871
"""
872872
try:
873-
import tensorstore as ts # type: ignore
873+
import tensorstore as ts
874874
except ImportError as e:
875875
raise ImportError(
876876
"tensorstore package is required for to_tensorstore()"
@@ -947,7 +947,7 @@ def open_group(
947947
storage_options = storage_options or {}
948948
if str(uri).startswith("s3://"):
949949
storage_options.setdefault("anon", True)
950-
mapper = get_mapper(uri, **storage_options) # type: ignore
950+
mapper = get_mapper(uri, **storage_options)
951951

952952
if not isinstance(mapper, FSMap): # pragma: no cover
953953
raise TypeError(f"Expected FSMap from get_mapper, got {type(mapper)}")

src/yaozarrs/write/v05/_write.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,7 +1084,7 @@ def prepare(self) -> tuple[Path, dict[str, Any]]:
10841084
raise ValueError("No series added. Use add_series() before prepare().")
10851085

10861086
# Create root zarr.json with bioformats2raw.layout
1087-
bf2raw = Bf2Raw(bioformats2raw_layout=3) # type: ignore
1087+
bf2raw = Bf2Raw(bioformats2raw_layout=3) # ty: ignore[missing-argument,unknown-argument]
10881088
_create_zarr3_group(self._dest, bf2raw, self._overwrite)
10891089

10901090
# Create OME/zarr.json with series list
@@ -1133,7 +1133,7 @@ def _ensure_initialized(self) -> None:
11331133
return
11341134

11351135
# Create root zarr.json with bioformats2raw.layout
1136-
bf2raw = Bf2Raw(bioformats2raw_layout=3) # type: ignore
1136+
bf2raw = Bf2Raw(bioformats2raw_layout=3) # ty: ignore[missing-argument,unknown-argument]
11371137
_create_zarr3_group(self._dest, bf2raw, self._overwrite)
11381138

11391139
# Create OME directory and write METADATA.ome.xml if provided
@@ -2463,16 +2463,16 @@ def _write_to_array(array: Any, data: ArrayLike, *, progress: bool) -> None:
24632463
with ctx:
24642464
# Handle both zarr and tensorstore
24652465
if hasattr(array, "store"): # zarr.Array
2466-
da.store(dask_data, array, lock=False) # type: ignore
2466+
da.store(dask_data, array, lock=False) # ty: ignore[invalid-argument-type]
24672467
else: # tensorstore
24682468
computed = dask_data.compute()
24692469
array[:].write(computed).result()
24702470

24712471
else:
24722472
if hasattr(array, "store"): # zarr.Array
2473-
array[:] = data # type: ignore
2473+
array[:] = data
24742474
else: # tensorstore
2475-
array[:].write(data).result() # type: ignore
2475+
array[:].write(data).result()
24762476

24772477

24782478
# ######################## Array Writing Functions #############################

tests/v04/test_bf2raw_v04.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
def test_bf2raw_v04():
22
from yaozarrs.v04._bf2raw import Bf2Raw
33

4-
Bf2Raw(bioformats2raw_layout=3) # type: ignore
4+
Bf2Raw(bioformats2raw_layout=3) # ty: ignore[missing-argument,unknown-argument]

tests/v04/test_images_v04.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,7 @@ def test_v04_axis_name_uniqueness_custom_validation() -> None:
714714
with pytest.raises(
715715
ValueError, match=r"Axis names must be unique\. Found duplicates"
716716
):
717-
_validate_axes_list(axes)
717+
_validate_axes_list(axes) # ty: ignore[invalid-argument-type]
718718

719719

720720
def test_multiscale_from_dims() -> None:

tests/v05/test_bf2raw_v05.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
def test_bf2raw_v05():
22
from yaozarrs.v05._bf2raw import Bf2Raw
33

4-
Bf2Raw(bioformats2raw_layout=3) # type: ignore
4+
Bf2Raw(bioformats2raw_layout=3) # ty: ignore[missing-argument,unknown-argument]

0 commit comments

Comments
 (0)