33import asyncio
44import dataclasses
55import warnings
6- from typing import TYPE_CHECKING , Any , Literal , NotRequired , TypedDict , cast
6+ from typing import TYPE_CHECKING , Any , Literal , NotRequired , TypeAlias , TypedDict , cast
77
88import numpy as np
99import numpy .typing as npt
3737 GroupMetadata ,
3838 create_hierarchy ,
3939)
40- from zarr .core .metadata import ArrayMetadataDict , ArrayV2Metadata , ArrayV3Metadata
40+ from zarr .core .metadata import ArrayMetadataDict , ArrayV2Metadata
4141from zarr .errors import (
4242 ArrayNotFoundError ,
4343 GroupNotFoundError ,
5858 from zarr .core .chunk_key_encodings import ChunkKeyEncoding
5959 from zarr .core .metadata .v2 import CompressorLikev2
6060 from zarr .storage import StoreLike
61+ from zarr .types import AnyArray , AnyAsyncArray
6162
6263 # TODO: this type could use some more thought
63- ArrayLike = AsyncArray [ ArrayV2Metadata ] | AsyncArray [ ArrayV3Metadata ] | Array | npt .NDArray [Any ]
64+ ArrayLike : TypeAlias = AnyAsyncArray | AnyArray | npt .NDArray [Any ]
6465 PathLike = str
6566
6667__all__ = [
@@ -335,7 +336,7 @@ async def open(
335336 path : str | None = None ,
336337 storage_options : dict [str , Any ] | None = None ,
337338 ** kwargs : Any , # TODO: type kwargs as valid args to open_array
338- ) -> AsyncArray [ ArrayV2Metadata ] | AsyncArray [ ArrayV3Metadata ] | AsyncGroup :
339+ ) -> AnyAsyncArray | AsyncGroup :
339340 """Convenience function to open a group or array using file-mode-like semantics.
340341
341342 Parameters
@@ -601,9 +602,7 @@ async def tree(grp: AsyncGroup, expand: bool | None = None, level: int | None =
601602 return await grp .tree (expand = expand , level = level )
602603
603604
604- async def array (
605- data : npt .ArrayLike | Array , ** kwargs : Any
606- ) -> AsyncArray [ArrayV2Metadata ] | AsyncArray [ArrayV3Metadata ]:
605+ async def array (data : npt .ArrayLike | AnyArray , ** kwargs : Any ) -> AnyAsyncArray :
607606 """Create an array filled with `data`.
608607
609608 Parameters
@@ -919,7 +918,7 @@ async def create(
919918 storage_options : dict [str , Any ] | None = None ,
920919 config : ArrayConfigLike | None = None ,
921920 ** kwargs : Any ,
922- ) -> AsyncArray [ ArrayV2Metadata ] | AsyncArray [ ArrayV3Metadata ] :
921+ ) -> AnyAsyncArray :
923922 """Create an array.
924923
925924 Parameters
@@ -1106,9 +1105,7 @@ async def create(
11061105 )
11071106
11081107
1109- async def empty (
1110- shape : tuple [int , ...], ** kwargs : Any
1111- ) -> AsyncArray [ArrayV2Metadata ] | AsyncArray [ArrayV3Metadata ]:
1108+ async def empty (shape : tuple [int , ...], ** kwargs : Any ) -> AnyAsyncArray :
11121109 """Create an empty array with the specified shape. The contents will be filled with the
11131110 specified fill value or zeros if no fill value is provided.
11141111
@@ -1128,9 +1125,7 @@ async def empty(
11281125 return await create (shape = shape , ** kwargs )
11291126
11301127
1131- async def empty_like (
1132- a : ArrayLike , ** kwargs : Any
1133- ) -> AsyncArray [ArrayV2Metadata ] | AsyncArray [ArrayV3Metadata ]:
1128+ async def empty_like (a : ArrayLike , ** kwargs : Any ) -> AnyAsyncArray :
11341129 """Create an empty array like `a`. The contents will be filled with the
11351130 array's fill value or zeros if no fill value is provided.
11361131
@@ -1159,9 +1154,7 @@ async def empty_like(
11591154
11601155
11611156# TODO: add type annotations for fill_value and kwargs
1162- async def full (
1163- shape : tuple [int , ...], fill_value : Any , ** kwargs : Any
1164- ) -> AsyncArray [ArrayV2Metadata ] | AsyncArray [ArrayV3Metadata ]:
1157+ async def full (shape : tuple [int , ...], fill_value : Any , ** kwargs : Any ) -> AnyAsyncArray :
11651158 """Create an array, with `fill_value` being used as the default value for
11661159 uninitialized portions of the array.
11671160
@@ -1183,9 +1176,7 @@ async def full(
11831176
11841177
11851178# TODO: add type annotations for kwargs
1186- async def full_like (
1187- a : ArrayLike , ** kwargs : Any
1188- ) -> AsyncArray [ArrayV2Metadata ] | AsyncArray [ArrayV3Metadata ]:
1179+ async def full_like (a : ArrayLike , ** kwargs : Any ) -> AnyAsyncArray :
11891180 """Create a filled array like `a`.
11901181
11911182 Parameters
@@ -1206,9 +1197,7 @@ async def full_like(
12061197 return await full (** like_kwargs ) # type: ignore[arg-type]
12071198
12081199
1209- async def ones (
1210- shape : tuple [int , ...], ** kwargs : Any
1211- ) -> AsyncArray [ArrayV2Metadata ] | AsyncArray [ArrayV3Metadata ]:
1200+ async def ones (shape : tuple [int , ...], ** kwargs : Any ) -> AnyAsyncArray :
12121201 """Create an array, with one being used as the default value for
12131202 uninitialized portions of the array.
12141203
@@ -1227,9 +1216,7 @@ async def ones(
12271216 return await create (shape = shape , fill_value = 1 , ** kwargs )
12281217
12291218
1230- async def ones_like (
1231- a : ArrayLike , ** kwargs : Any
1232- ) -> AsyncArray [ArrayV2Metadata ] | AsyncArray [ArrayV3Metadata ]:
1219+ async def ones_like (a : ArrayLike , ** kwargs : Any ) -> AnyAsyncArray :
12331220 """Create an array of ones like `a`.
12341221
12351222 Parameters
@@ -1256,7 +1243,7 @@ async def open_array(
12561243 path : PathLike = "" ,
12571244 storage_options : dict [str , Any ] | None = None ,
12581245 ** kwargs : Any , # TODO: type kwargs as valid args to save
1259- ) -> AsyncArray [ ArrayV2Metadata ] | AsyncArray [ ArrayV3Metadata ] :
1246+ ) -> AnyAsyncArray :
12601247 """Open an array using file-mode-like semantics.
12611248
12621249 Parameters
@@ -1307,9 +1294,7 @@ async def open_array(
13071294 raise ArrayNotFoundError (msg ) from err
13081295
13091296
1310- async def open_like (
1311- a : ArrayLike , path : str , ** kwargs : Any
1312- ) -> AsyncArray [ArrayV3Metadata ] | AsyncArray [ArrayV2Metadata ]:
1297+ async def open_like (a : ArrayLike , path : str , ** kwargs : Any ) -> AnyAsyncArray :
13131298 """Open a persistent array like `a`.
13141299
13151300 Parameters
@@ -1332,9 +1317,7 @@ async def open_like(
13321317 return await open_array (path = path , ** like_kwargs ) # type: ignore[arg-type]
13331318
13341319
1335- async def zeros (
1336- shape : tuple [int , ...], ** kwargs : Any
1337- ) -> AsyncArray [ArrayV2Metadata ] | AsyncArray [ArrayV3Metadata ]:
1320+ async def zeros (shape : tuple [int , ...], ** kwargs : Any ) -> AnyAsyncArray :
13381321 """Create an array, with zero being used as the default value for
13391322 uninitialized portions of the array.
13401323
@@ -1353,9 +1336,7 @@ async def zeros(
13531336 return await create (shape = shape , fill_value = 0 , ** kwargs )
13541337
13551338
1356- async def zeros_like (
1357- a : ArrayLike , ** kwargs : Any
1358- ) -> AsyncArray [ArrayV2Metadata ] | AsyncArray [ArrayV3Metadata ]:
1339+ async def zeros_like (a : ArrayLike , ** kwargs : Any ) -> AnyAsyncArray :
13591340 """Create an array of zeros like `a`.
13601341
13611342 Parameters
0 commit comments