Skip to content

Commit 444e096

Browse files
committed
fix typing errors
after zarr-developers/zarr-python#3304 we need to be specific about if we have V2 or V3 arrays
1 parent f9e2ea4 commit 444e096

File tree

4 files changed

+20
-9
lines changed

4 files changed

+20
-9
lines changed

icechunk-python/python/icechunk/dask.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import functools
22
from collections.abc import Callable, Mapping
3-
from typing import Any, ParamSpec, TypeAlias, TypeVar
3+
from typing import TYPE_CHECKING, Any, ParamSpec, TypeAlias, TypeVar
44

55
import numpy as np
66
from packaging.version import Version
@@ -13,6 +13,9 @@
1313
from icechunk.distributed import extract_session, merge_sessions
1414
from icechunk.session import ForkSession
1515

16+
if TYPE_CHECKING:
17+
from zarr.core.metadata import ArrayV3Metadata
18+
1619
SimpleGraph: TypeAlias = Mapping[tuple[str, int], tuple[Any, ...]]
1720

1821

@@ -57,7 +60,7 @@ def _assert_correct_dask_version() -> None:
5760
def store_dask(
5861
*,
5962
sources: list[Array],
60-
targets: list[zarr.Array],
63+
targets: list[zarr.Array[ArrayV3Metadata]],
6164
regions: list[tuple[slice, ...]] | None = None,
6265
split_every: int | None = None,
6366
**store_kwargs: Any,

icechunk-python/python/icechunk/distributed.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
# distributed utility functions
22
from collections.abc import Generator, Iterable
3-
from typing import Any, cast
3+
from typing import TYPE_CHECKING, Any, cast
44

55
import zarr
66
from icechunk import IcechunkStore
77
from icechunk.session import ForkSession, Session
88

9+
if TYPE_CHECKING:
10+
from zarr.core.metadata import ArrayV3Metadata
11+
912
__all__ = [
1013
"extract_session",
1114
"merge_sessions",
@@ -25,7 +28,7 @@ def _flatten(seq: Iterable[Any], container: type = list) -> Generator[Any, None,
2528

2629

2730
def extract_session(
28-
zarray: zarr.Array, axis: Any = None, keepdims: Any = None
31+
zarray: zarr.Array[ArrayV3Metadata], axis: Any = None, keepdims: Any = None
2932
) -> Session:
3033
"""
3134
Extract Icechunk Session from a zarr Array, useful for distributed array computing frameworks.

icechunk-python/python/icechunk/testing/strategies.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
from collections.abc import Iterable
2-
from typing import cast
2+
from typing import TYPE_CHECKING, cast
33

44
import hypothesis.strategies as st
55

66
import icechunk as ic
77
import zarr
8-
from zarr.core.metadata import ArrayV3Metadata
8+
9+
if TYPE_CHECKING:
10+
from zarr.core.metadata import ArrayV3Metadata
911

1012

1113
@st.composite
1214
def splitting_configs(
13-
draw: st.DrawFn, *, arrays: Iterable[zarr.Array]
15+
draw: st.DrawFn, *, arrays: Iterable[zarr.Array[ArrayV3Metadata]]
1416
) -> ic.ManifestSplittingConfig:
1517
config_dict: dict[
1618
ic.ManifestSplitCondition,

icechunk-python/python/icechunk/xarray.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from collections.abc import Hashable, Mapping, MutableMapping
22
from dataclasses import dataclass, field
33
from importlib.util import find_spec
4-
from typing import Any, Literal, overload
4+
from typing import TYPE_CHECKING, Any, Literal, overload
55

66
import numpy as np
77
from packaging.version import Version
@@ -15,6 +15,9 @@
1515
from xarray.backends.common import ArrayWriter
1616
from xarray.backends.zarr import ZarrStore
1717

18+
if TYPE_CHECKING:
19+
from zarr.core.metadata import ArrayV3Metadata
20+
1821
__all__ = ["to_icechunk"]
1922

2023
Region = Mapping[str, slice | Literal["auto"]] | Literal["auto"] | None
@@ -57,7 +60,7 @@ def __init__(self) -> None:
5760
super().__init__() # type: ignore[no-untyped-call]
5861

5962
self.eager_sources: list[np.ndarray[Any, Any]] = []
60-
self.eager_targets: list[zarr.Array] = []
63+
self.eager_targets: list[zarr.Array[ArrayV3Metadata]] = []
6164
self.eager_regions: list[tuple[slice, ...]] = []
6265

6366
def add(self, source: Any, target: Any, region: Any = None) -> Any:

0 commit comments

Comments
 (0)