Skip to content

Commit 9479d57

Browse files
committed
Add async array v2 and v3 types
1 parent f97296b commit 9479d57

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
@@ -310,15 +310,15 @@ class AsyncArray(Generic[T_ArrayMetadata]):
310310

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

319319
@overload
320320
def __init__(
321-
self: AsyncArray[ArrayV3Metadata],
321+
self: AsyncArrayV3,
322322
metadata: ArrayV3Metadata | ArrayV3MetadataDict,
323323
store_path: StorePath,
324324
config: ArrayConfigLike | None = None,
@@ -364,7 +364,7 @@ async def create(
364364
overwrite: bool = False,
365365
data: npt.ArrayLike | None = None,
366366
config: ArrayConfigLike | None = None,
367-
) -> AsyncArray[ArrayV2Metadata]: ...
367+
) -> AsyncArrayV2: ...
368368

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

398398
@overload
399399
@classmethod
@@ -421,7 +421,7 @@ async def create(
421421
overwrite: bool = False,
422422
data: npt.ArrayLike | None = None,
423423
config: ArrayConfigLike | None = None,
424-
) -> AsyncArray[ArrayV3Metadata]: ...
424+
) -> AsyncArrayV3: ...
425425

426426
@overload
427427
@classmethod
@@ -796,7 +796,7 @@ async def _create_v3(
796796
dimension_names: DimensionNames = None,
797797
attributes: dict[str, JSON] | None = None,
798798
overwrite: bool = False,
799-
) -> AsyncArray[ArrayV3Metadata]:
799+
) -> AsyncArrayV3:
800800
if overwrite:
801801
if store_path.store.supports_deletes:
802802
await store_path.delete_dir()
@@ -877,7 +877,7 @@ async def _create_v2(
877877
compressor: CompressorLike = "auto",
878878
attributes: dict[str, JSON] | None = None,
879879
overwrite: bool = False,
880-
) -> AsyncArray[ArrayV2Metadata]:
880+
) -> AsyncArrayV2:
881881
if overwrite:
882882
if store_path.store.supports_deletes:
883883
await store_path.delete_dir()
@@ -937,7 +937,7 @@ def from_dict(
937937
938938
Returns
939939
-------
940-
AsyncArray[ArrayV3Metadata] or AsyncArray[ArrayV2Metadata]
940+
AsyncArrayV3 or AsyncArrayV2
941941
The created Zarr array, either using Zarr format 2 or 3 metadata based on the provided data.
942942
943943
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

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

113113

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

117117

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

121121

122122
@overload
@@ -3556,15 +3556,11 @@ def _build_metadata_v2(
35563556

35573557

35583558
@overload
3559-
def _build_node(
3560-
*, store: Store, path: str, metadata: ArrayV2Metadata
3561-
) -> AsyncArray[ArrayV2Metadata]: ...
3559+
def _build_node(*, store: Store, path: str, metadata: ArrayV2Metadata) -> AsyncArrayV2: ...
35623560

35633561

35643562
@overload
3565-
def _build_node(
3566-
*, store: Store, path: str, metadata: ArrayV3Metadata
3567-
) -> AsyncArray[ArrayV3Metadata]: ...
3563+
def _build_node(*, store: Store, path: str, metadata: ArrayV3Metadata) -> AsyncArrayV3: ...
35683564

35693565

35703566
@overload
@@ -3587,7 +3583,7 @@ def _build_node(
35873583
raise ValueError(f"Unexpected metadata type: {type(metadata)}") # pragma: no cover
35883584

35893585

3590-
async def _get_node_v2(store: Store, path: str) -> AsyncArray[ArrayV2Metadata] | AsyncGroup:
3586+
async def _get_node_v2(store: Store, path: str) -> AsyncArrayV2 | AsyncGroup:
35913587
"""
35923588
Read a Zarr v2 AsyncArray or AsyncGroup from a path in a Store.
35933589
@@ -3606,7 +3602,7 @@ async def _get_node_v2(store: Store, path: str) -> AsyncArray[ArrayV2Metadata] |
36063602
return _build_node(store=store, path=path, metadata=metadata)
36073603

36083604

3609-
async def _get_node_v3(store: Store, path: str) -> AsyncArray[ArrayV3Metadata] | AsyncGroup:
3605+
async def _get_node_v3(store: Store, path: str) -> AsyncArrayV3 | AsyncGroup:
36103606
"""
36113607
Read a Zarr v3 AsyncArray or AsyncGroup from a path in a Store.
36123608

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)