Skip to content

Commit d8aaaba

Browse files
committed
Add async array v2 and v3 types
1 parent f2c4c5a commit d8aaaba

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
@@ -72,7 +72,7 @@
7272
from zarr.core.chunk_key_encodings import ChunkKeyEncodingLike
7373
from zarr.core.common import MemoryOrder
7474
from zarr.core.dtype import ZDTypeLike
75-
from zarr.types import AnyArray, AnyAsyncArray, ArrayV2, ArrayV3
75+
from zarr.types import AnyArray, AnyAsyncArray, ArrayV2, ArrayV3, AsyncArrayV2, AsyncArrayV3
7676

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

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

107107

108108
@overload
109-
def _parse_async_node(node: AsyncArray[ArrayV3Metadata]) -> ArrayV3: ...
109+
def _parse_async_node(node: AsyncArrayV3) -> ArrayV3: ...
110110

111111

112112
@overload
113-
def _parse_async_node(node: AsyncArray[ArrayV2Metadata]) -> ArrayV2: ...
113+
def _parse_async_node(node: AsyncArrayV2) -> ArrayV2: ...
114114

115115

116116
@overload
@@ -3542,15 +3542,11 @@ def _build_metadata_v2(
35423542

35433543

35443544
@overload
3545-
def _build_node(
3546-
*, store: Store, path: str, metadata: ArrayV2Metadata
3547-
) -> AsyncArray[ArrayV2Metadata]: ...
3545+
def _build_node(*, store: Store, path: str, metadata: ArrayV2Metadata) -> AsyncArrayV2: ...
35483546

35493547

35503548
@overload
3551-
def _build_node(
3552-
*, store: Store, path: str, metadata: ArrayV3Metadata
3553-
) -> AsyncArray[ArrayV3Metadata]: ...
3549+
def _build_node(*, store: Store, path: str, metadata: ArrayV3Metadata) -> AsyncArrayV3: ...
35543550

35553551

35563552
@overload
@@ -3573,7 +3569,7 @@ def _build_node(
35733569
raise ValueError(f"Unexpected metadata type: {type(metadata)}") # pragma: no cover
35743570

35753571

3576-
async def _get_node_v2(store: Store, path: str) -> AsyncArray[ArrayV2Metadata] | AsyncGroup:
3572+
async def _get_node_v2(store: Store, path: str) -> AsyncArrayV2 | AsyncGroup:
35773573
"""
35783574
Read a Zarr v2 AsyncArray or AsyncGroup from a path in a Store.
35793575
@@ -3592,7 +3588,7 @@ async def _get_node_v2(store: Store, path: str) -> AsyncArray[ArrayV2Metadata] |
35923588
return _build_node(store=store, path=path, metadata=metadata)
35933589

35943590

3595-
async def _get_node_v3(store: Store, path: str) -> AsyncArray[ArrayV3Metadata] | AsyncGroup:
3591+
async def _get_node_v3(store: Store, path: str) -> AsyncArrayV3 | AsyncGroup:
35963592
"""
35973593
Read a Zarr v3 AsyncArray or AsyncGroup from a path in a Store.
35983594

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)