Skip to content

Commit 6d81835

Browse files
committed
Add async array v2 and v3 types
1 parent d9986d0 commit 6d81835

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
@@ -140,7 +140,7 @@
140140
from zarr.core.dtype.wrapper import TBaseDType, TBaseScalar
141141
from zarr.core.group import AsyncGroup
142142
from zarr.storage import StoreLike
143-
from zarr.types import AnyArray, AnyAsyncArray
143+
from zarr.types import AnyArray, AnyAsyncArray, AsyncArrayV2, AsyncArrayV3
144144

145145

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

295295
@overload
296296
def __init__(
297-
self: AsyncArray[ArrayV2Metadata],
297+
self: AsyncArrayV2,
298298
metadata: ArrayV2Metadata | ArrayV2MetadataDict,
299299
store_path: StorePath,
300300
config: ArrayConfigLike | None = None,
301301
) -> None: ...
302302

303303
@overload
304304
def __init__(
305-
self: AsyncArray[ArrayV3Metadata],
305+
self: AsyncArrayV3,
306306
metadata: ArrayV3Metadata | ArrayV3MetadataDict,
307307
store_path: StorePath,
308308
config: ArrayConfigLike | None = None,
@@ -348,7 +348,7 @@ async def create(
348348
overwrite: bool = False,
349349
data: npt.ArrayLike | None = None,
350350
config: ArrayConfigLike | None = None,
351-
) -> AsyncArray[ArrayV2Metadata]: ...
351+
) -> AsyncArrayV2: ...
352352

353353
# this overload defines the function signature when zarr_format is 3
354354
@overload
@@ -377,7 +377,7 @@ async def create(
377377
overwrite: bool = False,
378378
data: npt.ArrayLike | None = None,
379379
config: ArrayConfigLike | None = None,
380-
) -> AsyncArray[ArrayV3Metadata]: ...
380+
) -> AsyncArrayV3: ...
381381

382382
@overload
383383
@classmethod
@@ -405,7 +405,7 @@ async def create(
405405
overwrite: bool = False,
406406
data: npt.ArrayLike | None = None,
407407
config: ArrayConfigLike | None = None,
408-
) -> AsyncArray[ArrayV3Metadata]: ...
408+
) -> AsyncArrayV3: ...
409409

410410
@overload
411411
@classmethod
@@ -780,7 +780,7 @@ async def _create_v3(
780780
dimension_names: DimensionNames = None,
781781
attributes: dict[str, JSON] | None = None,
782782
overwrite: bool = False,
783-
) -> AsyncArray[ArrayV3Metadata]:
783+
) -> AsyncArrayV3:
784784
if overwrite:
785785
if store_path.store.supports_deletes:
786786
await store_path.delete_dir()
@@ -861,7 +861,7 @@ async def _create_v2(
861861
compressor: CompressorLike = "auto",
862862
attributes: dict[str, JSON] | None = None,
863863
overwrite: bool = False,
864-
) -> AsyncArray[ArrayV2Metadata]:
864+
) -> AsyncArrayV2:
865865
if overwrite:
866866
if store_path.store.supports_deletes:
867867
await store_path.delete_dir()
@@ -921,7 +921,7 @@ def from_dict(
921921
922922
Returns
923923
-------
924-
AsyncArray[ArrayV3Metadata] or AsyncArray[ArrayV2Metadata]
924+
AsyncArrayV3 or AsyncArrayV2
925925
The created Zarr array, either using Zarr format 2 or 3 metadata based on the provided data.
926926
927927
Raises

src/zarr/core/group.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
from zarr.core.chunk_key_encodings import ChunkKeyEncodingLike
7474
from zarr.core.common import MemoryOrder
7575
from zarr.core.dtype import ZDTypeLike
76-
from zarr.types import AnyArray, AnyAsyncArray, ArrayV2, ArrayV3
76+
from zarr.types import AnyArray, AnyAsyncArray, ArrayV2, ArrayV3, AsyncArrayV2, AsyncArrayV3
7777

7878
logger = logging.getLogger("zarr.group")
7979

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

108108

109109
@overload
110-
def _parse_async_node(node: AsyncArray[ArrayV3Metadata]) -> ArrayV3: ...
110+
def _parse_async_node(node: AsyncArrayV3) -> ArrayV3: ...
111111

112112

113113
@overload
114-
def _parse_async_node(node: AsyncArray[ArrayV2Metadata]) -> ArrayV2: ...
114+
def _parse_async_node(node: AsyncArrayV2) -> ArrayV2: ...
115115

116116

117117
@overload
@@ -3552,15 +3552,11 @@ def _build_metadata_v2(
35523552

35533553

35543554
@overload
3555-
def _build_node(
3556-
*, store: Store, path: str, metadata: ArrayV2Metadata
3557-
) -> AsyncArray[ArrayV2Metadata]: ...
3555+
def _build_node(*, store: Store, path: str, metadata: ArrayV2Metadata) -> AsyncArrayV2: ...
35583556

35593557

35603558
@overload
3561-
def _build_node(
3562-
*, store: Store, path: str, metadata: ArrayV3Metadata
3563-
) -> AsyncArray[ArrayV3Metadata]: ...
3559+
def _build_node(*, store: Store, path: str, metadata: ArrayV3Metadata) -> AsyncArrayV3: ...
35643560

35653561

35663562
@overload
@@ -3583,7 +3579,7 @@ def _build_node(
35833579
raise ValueError(f"Unexpected metadata type: {type(metadata)}") # pragma: no cover
35843580

35853581

3586-
async def _get_node_v2(store: Store, path: str) -> AsyncArray[ArrayV2Metadata] | AsyncGroup:
3582+
async def _get_node_v2(store: Store, path: str) -> AsyncArrayV2 | AsyncGroup:
35873583
"""
35883584
Read a Zarr v2 AsyncArray or AsyncGroup from a path in a Store.
35893585
@@ -3602,7 +3598,7 @@ async def _get_node_v2(store: Store, path: str) -> AsyncArray[ArrayV2Metadata] |
36023598
return _build_node(store=store, path=path, metadata=metadata)
36033599

36043600

3605-
async def _get_node_v3(store: Store, path: str) -> AsyncArray[ArrayV3Metadata] | AsyncGroup:
3601+
async def _get_node_v3(store: Store, path: str) -> AsyncArrayV3 | AsyncGroup:
36063602
"""
36073603
Read a Zarr v3 AsyncArray or AsyncGroup from a path in a Store.
36083604

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)