Skip to content

Commit 37a930e

Browse files
committed
Add async array v2 and v3 types
1 parent a0ddd2e commit 37a930e

File tree

3 files changed

+21
-20
lines changed

3 files changed

+21
-20
lines changed

src/zarr/core/array.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@
144144
from zarr.codecs.sharding import ShardingCodecIndexLocation
145145
from zarr.core.dtype.wrapper import TBaseDType, TBaseScalar
146146
from zarr.storage import StoreLike
147-
from zarr.types import AnyArray, AnyAsyncArray
147+
from zarr.types import AnyArray, AnyAsyncArray, AsyncArrayV2, AsyncArrayV3
148148

149149

150150
# Array and AsyncArray are defined in the base ``zarr`` namespace
@@ -311,15 +311,15 @@ class AsyncArray(Generic[T_ArrayMetadata]):
311311

312312
@overload
313313
def __init__(
314-
self: AsyncArray[ArrayV2Metadata],
314+
self: AsyncArrayV2,
315315
metadata: ArrayV2Metadata | ArrayV2MetadataDict,
316316
store_path: StorePath,
317317
config: ArrayConfigLike | None = None,
318318
) -> None: ...
319319

320320
@overload
321321
def __init__(
322-
self: AsyncArray[ArrayV3Metadata],
322+
self: AsyncArrayV3,
323323
metadata: ArrayV3Metadata | ArrayV3MetadataDict,
324324
store_path: StorePath,
325325
config: ArrayConfigLike | None = None,
@@ -365,7 +365,7 @@ async def create(
365365
overwrite: bool = False,
366366
data: npt.ArrayLike | None = None,
367367
config: ArrayConfigLike | None = None,
368-
) -> AsyncArray[ArrayV2Metadata]: ...
368+
) -> AsyncArrayV2: ...
369369

370370
# this overload defines the function signature when zarr_format is 3
371371
@overload
@@ -394,7 +394,7 @@ async def create(
394394
overwrite: bool = False,
395395
data: npt.ArrayLike | None = None,
396396
config: ArrayConfigLike | None = None,
397-
) -> AsyncArray[ArrayV3Metadata]: ...
397+
) -> AsyncArrayV3: ...
398398

399399
@overload
400400
@classmethod
@@ -422,7 +422,7 @@ async def create(
422422
overwrite: bool = False,
423423
data: npt.ArrayLike | None = None,
424424
config: ArrayConfigLike | None = None,
425-
) -> AsyncArray[ArrayV3Metadata]: ...
425+
) -> AsyncArrayV3: ...
426426

427427
@overload
428428
@classmethod
@@ -804,7 +804,7 @@ async def _create_v3(
804804
dimension_names: DimensionNames = None,
805805
attributes: dict[str, JSON] | None = None,
806806
overwrite: bool = False,
807-
) -> AsyncArray[ArrayV3Metadata]:
807+
) -> AsyncArrayV3:
808808
if overwrite:
809809
if store_path.store.supports_deletes:
810810
await store_path.delete_dir()
@@ -885,7 +885,7 @@ async def _create_v2(
885885
compressor: CompressorLike = "auto",
886886
attributes: dict[str, JSON] | None = None,
887887
overwrite: bool = False,
888-
) -> AsyncArray[ArrayV2Metadata]:
888+
) -> AsyncArrayV2:
889889
if overwrite:
890890
if store_path.store.supports_deletes:
891891
await store_path.delete_dir()
@@ -945,7 +945,7 @@ def from_dict(
945945
946946
Returns
947947
-------
948-
AsyncArray[ArrayV3Metadata] or AsyncArray[ArrayV2Metadata]
948+
AsyncArrayV3 or AsyncArrayV2
949949
The created Zarr array, either using Zarr format 2 or 3 metadata based on the provided data.
950950
951951
Raises

src/zarr/core/group.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
from zarr.core.chunk_key_encodings import ChunkKeyEncodingLike
8080
from zarr.core.common import MemoryOrder
8181
from zarr.core.dtype import ZDTypeLike
82-
from zarr.types import AnyArray, AnyAsyncArray, ArrayV2, ArrayV3
82+
from zarr.types import AnyArray, AnyAsyncArray, ArrayV2, ArrayV3, AsyncArrayV2, AsyncArrayV3
8383

8484
logger = logging.getLogger("zarr.group")
8585

@@ -114,11 +114,11 @@ def parse_attributes(data: Any) -> dict[str, Any]:
114114

115115

116116
@overload
117-
def _parse_async_node(node: AsyncArray[ArrayV3Metadata]) -> ArrayV3: ...
117+
def _parse_async_node(node: AsyncArrayV3) -> ArrayV3: ...
118118

119119

120120
@overload
121-
def _parse_async_node(node: AsyncArray[ArrayV2Metadata]) -> ArrayV2: ...
121+
def _parse_async_node(node: AsyncArrayV2) -> ArrayV2: ...
122122

123123

124124
@overload
@@ -3702,15 +3702,11 @@ def _build_metadata_v2(
37023702

37033703

37043704
@overload
3705-
def _build_node(
3706-
*, store: Store, path: str, metadata: ArrayV2Metadata
3707-
) -> AsyncArray[ArrayV2Metadata]: ...
3705+
def _build_node(*, store: Store, path: str, metadata: ArrayV2Metadata) -> AsyncArrayV2: ...
37083706

37093707

37103708
@overload
3711-
def _build_node(
3712-
*, store: Store, path: str, metadata: ArrayV3Metadata
3713-
) -> AsyncArray[ArrayV3Metadata]: ...
3709+
def _build_node(*, store: Store, path: str, metadata: ArrayV3Metadata) -> AsyncArrayV3: ...
37143710

37153711

37163712
@overload
@@ -3733,7 +3729,7 @@ def _build_node(
37333729
raise ValueError(f"Unexpected metadata type: {type(metadata)}") # pragma: no cover
37343730

37353731

3736-
async def _get_node_v2(store: Store, path: str) -> AsyncArray[ArrayV2Metadata] | AsyncGroup:
3732+
async def _get_node_v2(store: Store, path: str) -> AsyncArrayV2 | AsyncGroup:
37373733
"""
37383734
Read a Zarr v2 AsyncArray or AsyncGroup from a path in a Store.
37393735
@@ -3752,7 +3748,7 @@ async def _get_node_v2(store: Store, path: str) -> AsyncArray[ArrayV2Metadata] |
37523748
return _build_node(store=store, path=path, metadata=metadata)
37533749

37543750

3755-
async def _get_node_v3(store: Store, path: str) -> AsyncArray[ArrayV3Metadata] | AsyncGroup:
3751+
async def _get_node_v3(store: Store, path: str) -> AsyncArrayV3 | AsyncGroup:
37563752
"""
37573753
Read a Zarr v3 AsyncArray or AsyncGroup from a path in a Store.
37583754

src/zarr/types.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
AnyAsyncArray: TypeAlias = AsyncArray[Any]
88
"""A Zarr format 2 or 3 `AsyncArray`"""
99

10+
AsyncArrayV2: TypeAlias = AsyncArray[ArrayV2Metadata]
11+
"""A Zarr format 2 `AsyncArray`"""
12+
13+
AsyncArrayV3: TypeAlias = AsyncArray[ArrayV3Metadata]
14+
"""A Zarr format 3 `AsyncArray`"""
1015

1116
AnyArray: TypeAlias = Array[Any]
1217
"""A Zarr format 2 or 3 `Array`"""

0 commit comments

Comments
 (0)