Skip to content

Commit 3893e55

Browse files
committed
add likeargs typeddict
1 parent cb99615 commit 3893e55

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/zarr/api/asynchronous.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import asyncio
44
import dataclasses
55
import warnings
6-
from typing import TYPE_CHECKING, Any, Literal, cast
6+
from typing import TYPE_CHECKING, Any, Literal, NotRequired, TypedDict, cast
77

88
import numpy as np
99
import numpy.typing as npt
@@ -38,13 +38,15 @@
3838
create_hierarchy,
3939
)
4040
from zarr.core.metadata import ArrayMetadataDict, ArrayV2Metadata, ArrayV3Metadata
41-
from zarr.core.metadata.v2 import _default_compressor, _default_filters
41+
from zarr.core.metadata.v2 import CompressorLikev2, _default_compressor, _default_filters
4242
from zarr.errors import NodeTypeValidationError
4343
from zarr.storage._common import make_store_path
4444

4545
if TYPE_CHECKING:
4646
from collections.abc import Iterable
4747

48+
import numcodecs
49+
4850
from zarr.abc.codec import Codec
4951
from zarr.core.buffer import NDArrayLikeOrScalar
5052
from zarr.core.chunk_key_encodings import ChunkKeyEncoding
@@ -116,10 +118,20 @@ def _get_shape_chunks(a: ArrayLike | Any) -> tuple[ChunkCoords | None, ChunkCoor
116118
return shape, chunks
117119

118120

119-
def _like_args(a: ArrayLike) -> dict[str, object]:
121+
class _LikeArgs(TypedDict):
122+
shape: NotRequired[ChunkCoords]
123+
chunks: NotRequired[ChunkCoords]
124+
dtype: NotRequired[np.dtype[np.generic]]
125+
order: NotRequired[Literal["C", "F"]]
126+
filters: NotRequired[tuple[numcodecs.abc.Codec, ...] | None]
127+
compressor: NotRequired[CompressorLikev2]
128+
codecs: NotRequired[tuple[Codec, ...]]
129+
130+
131+
def _like_args(a: ArrayLike) -> _LikeArgs:
120132
"""Set default values for shape and chunks if they are not present in the array-like object"""
121133

122-
new: dict[str, object] = {}
134+
new: _LikeArgs = {}
123135

124136
shape, chunks = _get_shape_chunks(a)
125137
if shape is not None:

0 commit comments

Comments
 (0)