Skip to content

Commit 67a0df6

Browse files
committed
Copy tom augsburger's overload
1 parent a82fb03 commit 67a0df6

File tree

1 file changed

+72
-8
lines changed

1 file changed

+72
-8
lines changed

src/zarr/core/array.py

Lines changed: 72 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from asyncio import gather
55
from dataclasses import dataclass, field, replace
66
from logging import getLogger
7-
from typing import TYPE_CHECKING, Any, Generic, Literal, TypeVar, cast
7+
from typing import TYPE_CHECKING, Any, Generic, Literal, TypeVar, cast, overload
88

99
import numpy as np
1010
import numpy.typing as npt
@@ -191,6 +191,72 @@ def __init__(
191191
object.__setattr__(self, "order", order_parsed)
192192
object.__setattr__(self, "codec_pipeline", create_codec_pipeline(metadata=metadata_parsed))
193193

194+
@overload
195+
@classmethod
196+
async def create(
197+
cls,
198+
store: StoreLike,
199+
*,
200+
# v2 and v3
201+
shape: ShapeLike,
202+
dtype: npt.DTypeLike,
203+
zarr_format: Literal[2],
204+
fill_value: Any | None = None,
205+
attributes: dict[str, JSON] | None = None,
206+
# v3 only
207+
chunk_shape: ChunkCoords | None = None,
208+
chunk_key_encoding: (
209+
ChunkKeyEncoding
210+
| tuple[Literal["default"], Literal[".", "/"]]
211+
| tuple[Literal["v2"], Literal[".", "/"]]
212+
| None
213+
) = None,
214+
codecs: Iterable[Codec | dict[str, JSON]] | None = None,
215+
dimension_names: Iterable[str] | None = None,
216+
# v2 only
217+
chunks: ShapeLike | None = None,
218+
dimension_separator: Literal[".", "/"] | None = None,
219+
order: Literal["C", "F"] | None = None,
220+
filters: list[dict[str, JSON]] | None = None,
221+
compressor: dict[str, JSON] | None = None,
222+
# runtime
223+
exists_ok: bool = False,
224+
data: npt.ArrayLike | None = None,
225+
) -> AsyncArray[ArrayV2Metadata]:...
226+
227+
@overload
228+
@classmethod
229+
async def create(
230+
cls,
231+
store: StoreLike,
232+
*,
233+
# v2 and v3
234+
shape: ShapeLike,
235+
dtype: npt.DTypeLike,
236+
zarr_format: Literal[3],
237+
fill_value: Any | None = None,
238+
attributes: dict[str, JSON] | None = None,
239+
# v3 only
240+
chunk_shape: ChunkCoords | None = None,
241+
chunk_key_encoding: (
242+
ChunkKeyEncoding
243+
| tuple[Literal["default"], Literal[".", "/"]]
244+
| tuple[Literal["v2"], Literal[".", "/"]]
245+
| None
246+
) = None,
247+
codecs: Iterable[Codec | dict[str, JSON]] | None = None,
248+
dimension_names: Iterable[str] | None = None,
249+
# v2 only
250+
chunks: ShapeLike | None = None,
251+
dimension_separator: Literal[".", "/"] | None = None,
252+
order: Literal["C", "F"] | None = None,
253+
filters: list[dict[str, JSON]] | None = None,
254+
compressor: dict[str, JSON] | None = None,
255+
# runtime
256+
exists_ok: bool = False,
257+
data: npt.ArrayLike | None = None,
258+
) -> AsyncArray[ArrayV3Metadata]:...
259+
194260
@classmethod
195261
async def create(
196262
cls,
@@ -347,9 +413,7 @@ async def _create_v3(
347413

348414
array = cls(metadata=metadata, store_path=store_path)
349415
await array._save_metadata(metadata, ensure_parents=True)
350-
# type inference is inconsistent here and seems to conclude
351-
# that array has type Array[ArrayV2Metadata]
352-
return array # type: ignore[return-value]
416+
return array
353417

354418
@classmethod
355419
async def _create_v2(
@@ -388,7 +452,7 @@ async def _create_v2(
388452
)
389453
array = cls(metadata=metadata, store_path=store_path)
390454
await array._save_metadata(metadata, ensure_parents=True)
391-
return array # type: ignore[return-value]
455+
return array
392456

393457
@classmethod
394458
def from_dict(
@@ -500,7 +564,7 @@ def _iter_chunk_coords(
500564
keyword is used, iteration will start at the chunk index specified by `origin`.
501565
The default behavior is to start at the origin of the grid coordinate space.
502566
If the `selection_shape` keyword is used, iteration will be bounded over a contiguous region
503-
ranging from `[origin, origin + selection_shape]`, where the upper bound is exclusive as
567+
ranging from `[origin, origin selection_shape]`, where the upper bound is exclusive as
504568
per python indexing conventions.
505569
506570
Parameters
@@ -2314,10 +2378,10 @@ def resize(self, new_shape: ChunkCoords) -> Array:
23142378
the data falling outside the new array but inside the boundary chunks
23152379
would be restored by a subsequent resize operation that grows the array size.
23162380
"""
2317-
return type(self)(sync(self._async_array.resize(new_shape))) # type: ignore[arg-type]
2381+
return type(self)(sync(self._async_array.resize(new_shape)))
23182382

23192383
def update_attributes(self, new_attributes: dict[str, JSON]) -> Array:
2320-
return type(self)(sync(self._async_array.update_attributes(new_attributes))) # type: ignore[arg-type]
2384+
return type(self)(sync(self._async_array.update_attributes(new_attributes)))
23212385

23222386
def __repr__(self) -> str:
23232387
return f"<Array {self.store_path} shape={self.shape} dtype={self.dtype}>"

0 commit comments

Comments
 (0)