Skip to content

Commit 1a46787

Browse files
committed
Add async array v2 and v3 types
1 parent 2b418c0 commit 1a46787

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
@@ -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

@@ -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
@@ -3558,15 +3558,11 @@ def _build_metadata_v2(
35583558

35593559

35603560
@overload
3561-
def _build_node(
3562-
*, store: Store, path: str, metadata: ArrayV2Metadata
3563-
) -> AsyncArray[ArrayV2Metadata]: ...
3561+
def _build_node(*, store: Store, path: str, metadata: ArrayV2Metadata) -> AsyncArrayV2: ...
35643562

35653563

35663564
@overload
3567-
def _build_node(
3568-
*, store: Store, path: str, metadata: ArrayV3Metadata
3569-
) -> AsyncArray[ArrayV3Metadata]: ...
3565+
def _build_node(*, store: Store, path: str, metadata: ArrayV3Metadata) -> AsyncArrayV3: ...
35703566

35713567

35723568
@overload
@@ -3589,7 +3585,7 @@ def _build_node(
35893585
raise ValueError(f"Unexpected metadata type: {type(metadata)}") # pragma: no cover
35903586

35913587

3592-
async def _get_node_v2(store: Store, path: str) -> AsyncArray[ArrayV2Metadata] | AsyncGroup:
3588+
async def _get_node_v2(store: Store, path: str) -> AsyncArrayV2 | AsyncGroup:
35933589
"""
35943590
Read a Zarr v2 AsyncArray or AsyncGroup from a path in a Store.
35953591
@@ -3608,7 +3604,7 @@ async def _get_node_v2(store: Store, path: str) -> AsyncArray[ArrayV2Metadata] |
36083604
return _build_node(store=store, path=path, metadata=metadata)
36093605

36103606

3611-
async def _get_node_v3(store: Store, path: str) -> AsyncArray[ArrayV3Metadata] | AsyncGroup:
3607+
async def _get_node_v3(store: Store, path: str) -> AsyncArrayV3 | AsyncGroup:
36123608
"""
36133609
Read a Zarr v3 AsyncArray or AsyncGroup from a path in a Store.
36143610

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)