Skip to content

Commit 7e5515d

Browse files
committed
Add async array v2 and v3 types
1 parent de74a78 commit 7e5515d

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.core.dtype.wrapper import TBaseDType, TBaseScalar
145145
from zarr.core.group import AsyncGroup
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
@@ -797,7 +797,7 @@ async def _create_v3(
797797
dimension_names: DimensionNames = None,
798798
attributes: dict[str, JSON] | None = None,
799799
overwrite: bool = False,
800-
) -> AsyncArray[ArrayV3Metadata]:
800+
) -> AsyncArrayV3:
801801
if overwrite:
802802
if store_path.store.supports_deletes:
803803
await store_path.delete_dir()
@@ -878,7 +878,7 @@ async def _create_v2(
878878
compressor: CompressorLike = "auto",
879879
attributes: dict[str, JSON] | None = None,
880880
overwrite: bool = False,
881-
) -> AsyncArray[ArrayV2Metadata]:
881+
) -> AsyncArrayV2:
882882
if overwrite:
883883
if store_path.store.supports_deletes:
884884
await store_path.delete_dir()
@@ -938,7 +938,7 @@ def from_dict(
938938
939939
Returns
940940
-------
941-
AsyncArray[ArrayV3Metadata] or AsyncArray[ArrayV2Metadata]
941+
AsyncArrayV3 or AsyncArrayV2
942942
The created Zarr array, either using Zarr format 2 or 3 metadata based on the provided data.
943943
944944
Raises

src/zarr/core/group.py

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

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

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

114114

115115
@overload
116-
def _parse_async_node(node: AsyncArray[ArrayV3Metadata]) -> ArrayV3: ...
116+
def _parse_async_node(node: AsyncArrayV3) -> ArrayV3: ...
117117

118118

119119
@overload
120-
def _parse_async_node(node: AsyncArray[ArrayV2Metadata]) -> ArrayV2: ...
120+
def _parse_async_node(node: AsyncArrayV2) -> ArrayV2: ...
121121

122122

123123
@overload
@@ -3561,15 +3561,11 @@ def _build_metadata_v2(
35613561

35623562

35633563
@overload
3564-
def _build_node(
3565-
*, store: Store, path: str, metadata: ArrayV2Metadata
3566-
) -> AsyncArray[ArrayV2Metadata]: ...
3564+
def _build_node(*, store: Store, path: str, metadata: ArrayV2Metadata) -> AsyncArrayV2: ...
35673565

35683566

35693567
@overload
3570-
def _build_node(
3571-
*, store: Store, path: str, metadata: ArrayV3Metadata
3572-
) -> AsyncArray[ArrayV3Metadata]: ...
3568+
def _build_node(*, store: Store, path: str, metadata: ArrayV3Metadata) -> AsyncArrayV3: ...
35733569

35743570

35753571
@overload
@@ -3592,7 +3588,7 @@ def _build_node(
35923588
raise ValueError(f"Unexpected metadata type: {type(metadata)}") # pragma: no cover
35933589

35943590

3595-
async def _get_node_v2(store: Store, path: str) -> AsyncArray[ArrayV2Metadata] | AsyncGroup:
3591+
async def _get_node_v2(store: Store, path: str) -> AsyncArrayV2 | AsyncGroup:
35963592
"""
35973593
Read a Zarr v2 AsyncArray or AsyncGroup from a path in a Store.
35983594
@@ -3611,7 +3607,7 @@ async def _get_node_v2(store: Store, path: str) -> AsyncArray[ArrayV2Metadata] |
36113607
return _build_node(store=store, path=path, metadata=metadata)
36123608

36133609

3614-
async def _get_node_v3(store: Store, path: str) -> AsyncArray[ArrayV3Metadata] | AsyncGroup:
3610+
async def _get_node_v3(store: Store, path: str) -> AsyncArrayV3 | AsyncGroup:
36153611
"""
36163612
Read a Zarr v3 AsyncArray or AsyncGroup from a path in a Store.
36173613

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)