Skip to content

Commit 2b7317b

Browse files
committed
Add async array v2 and v3 types
1 parent 4798582 commit 2b7317b

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
@@ -806,7 +806,7 @@ async def _create_v3(
806806
dimension_names: DimensionNames = None,
807807
attributes: dict[str, JSON] | None = None,
808808
overwrite: bool = False,
809-
) -> AsyncArray[ArrayV3Metadata]:
809+
) -> AsyncArrayV3:
810810
if overwrite:
811811
if store_path.store.supports_deletes:
812812
await store_path.delete_dir()
@@ -887,7 +887,7 @@ async def _create_v2(
887887
compressor: CompressorLike = "auto",
888888
attributes: dict[str, JSON] | None = None,
889889
overwrite: bool = False,
890-
) -> AsyncArray[ArrayV2Metadata]:
890+
) -> AsyncArrayV2:
891891
if overwrite:
892892
if store_path.store.supports_deletes:
893893
await store_path.delete_dir()
@@ -947,7 +947,7 @@ def from_dict(
947947
948948
Returns
949949
-------
950-
AsyncArray[ArrayV3Metadata] or AsyncArray[ArrayV2Metadata]
950+
AsyncArrayV3 or AsyncArrayV2
951951
The created Zarr array, either using Zarr format 2 or 3 metadata based on the provided data.
952952
953953
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
@@ -3706,15 +3706,11 @@ def _build_metadata_v2(
37063706

37073707

37083708
@overload
3709-
def _build_node(
3710-
*, store: Store, path: str, metadata: ArrayV2Metadata
3711-
) -> AsyncArray[ArrayV2Metadata]: ...
3709+
def _build_node(*, store: Store, path: str, metadata: ArrayV2Metadata) -> AsyncArrayV2: ...
37123710

37133711

37143712
@overload
3715-
def _build_node(
3716-
*, store: Store, path: str, metadata: ArrayV3Metadata
3717-
) -> AsyncArray[ArrayV3Metadata]: ...
3713+
def _build_node(*, store: Store, path: str, metadata: ArrayV3Metadata) -> AsyncArrayV3: ...
37183714

37193715

37203716
@overload
@@ -3737,7 +3733,7 @@ def _build_node(
37373733
raise ValueError(f"Unexpected metadata type: {type(metadata)}") # pragma: no cover
37383734

37393735

3740-
async def _get_node_v2(store: Store, path: str) -> AsyncArray[ArrayV2Metadata] | AsyncGroup:
3736+
async def _get_node_v2(store: Store, path: str) -> AsyncArrayV2 | AsyncGroup:
37413737
"""
37423738
Read a Zarr v2 AsyncArray or AsyncGroup from a path in a Store.
37433739
@@ -3756,7 +3752,7 @@ async def _get_node_v2(store: Store, path: str) -> AsyncArray[ArrayV2Metadata] |
37563752
return _build_node(store=store, path=path, metadata=metadata)
37573753

37583754

3759-
async def _get_node_v3(store: Store, path: str) -> AsyncArray[ArrayV3Metadata] | AsyncGroup:
3755+
async def _get_node_v3(store: Store, path: str) -> AsyncArrayV3 | AsyncGroup:
37603756
"""
37613757
Read a Zarr v3 AsyncArray or AsyncGroup from a path in a Store.
37623758

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)