Skip to content

Commit d5c77f3

Browse files
committed
Add async array v2 and v3 types
1 parent 6ff833d commit d5c77f3

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
@@ -138,7 +138,7 @@
138138
from zarr.core.dtype.wrapper import TBaseDType, TBaseScalar
139139
from zarr.core.group import AsyncGroup
140140
from zarr.storage import StoreLike
141-
from zarr.types import AnyArray, AnyAsyncArray
141+
from zarr.types import AnyArray, AnyAsyncArray, AsyncArrayV2, AsyncArrayV3
142142

143143

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

293293
@overload
294294
def __init__(
295-
self: AsyncArray[ArrayV2Metadata],
295+
self: AsyncArrayV2,
296296
metadata: ArrayV2Metadata | ArrayV2MetadataDict,
297297
store_path: StorePath,
298298
config: ArrayConfigLike | None = None,
299299
) -> None: ...
300300

301301
@overload
302302
def __init__(
303-
self: AsyncArray[ArrayV3Metadata],
303+
self: AsyncArrayV3,
304304
metadata: ArrayV3Metadata | ArrayV3MetadataDict,
305305
store_path: StorePath,
306306
config: ArrayConfigLike | None = None,
@@ -346,7 +346,7 @@ async def create(
346346
overwrite: bool = False,
347347
data: npt.ArrayLike | None = None,
348348
config: ArrayConfigLike | None = None,
349-
) -> AsyncArray[ArrayV2Metadata]: ...
349+
) -> AsyncArrayV2: ...
350350

351351
# this overload defines the function signature when zarr_format is 3
352352
@overload
@@ -375,7 +375,7 @@ async def create(
375375
overwrite: bool = False,
376376
data: npt.ArrayLike | None = None,
377377
config: ArrayConfigLike | None = None,
378-
) -> AsyncArray[ArrayV3Metadata]: ...
378+
) -> AsyncArrayV3: ...
379379

380380
@overload
381381
@classmethod
@@ -403,7 +403,7 @@ async def create(
403403
overwrite: bool = False,
404404
data: npt.ArrayLike | None = None,
405405
config: ArrayConfigLike | None = None,
406-
) -> AsyncArray[ArrayV3Metadata]: ...
406+
) -> AsyncArrayV3: ...
407407

408408
@overload
409409
@classmethod
@@ -778,7 +778,7 @@ async def _create_v3(
778778
dimension_names: DimensionNames = None,
779779
attributes: dict[str, JSON] | None = None,
780780
overwrite: bool = False,
781-
) -> AsyncArray[ArrayV3Metadata]:
781+
) -> AsyncArrayV3:
782782
if overwrite:
783783
if store_path.store.supports_deletes:
784784
await store_path.delete_dir()
@@ -859,7 +859,7 @@ async def _create_v2(
859859
compressor: CompressorLike = "auto",
860860
attributes: dict[str, JSON] | None = None,
861861
overwrite: bool = False,
862-
) -> AsyncArray[ArrayV2Metadata]:
862+
) -> AsyncArrayV2:
863863
if overwrite:
864864
if store_path.store.supports_deletes:
865865
await store_path.delete_dir()
@@ -919,7 +919,7 @@ def from_dict(
919919
920920
Returns
921921
-------
922-
AsyncArray[ArrayV3Metadata] or AsyncArray[ArrayV2Metadata]
922+
AsyncArrayV3 or AsyncArrayV2
923923
The created Zarr array, either using Zarr format 2 or 3 metadata based on the provided data.
924924
925925
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)