Skip to content

Commit 01bd4b7

Browse files
committed
use Any to model input / output types of numcodec protocol
1 parent 931bf2f commit 01bd4b7

File tree

4 files changed

+18
-22
lines changed

4 files changed

+18
-22
lines changed

src/zarr/abc/numcodec.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
from typing import Self, TypeGuard
1+
from typing import Any, Self, TypeGuard
22

3-
from typing_extensions import Buffer, Protocol
4-
5-
from zarr.abc.codec import CodecJSON_V2
3+
from typing_extensions import Protocol
64

75

86
class Numcodec(Protocol):
@@ -12,14 +10,14 @@ class Numcodec(Protocol):
1210

1311
codec_id: str
1412

15-
def encode(self, buf: Buffer) -> Buffer: ...
13+
def encode(self, buf: Any) -> Any: ...
1614

17-
def decode(self, buf: Buffer, out: Buffer | None = None) -> Buffer: ...
15+
def decode(self, buf: Any, out: Any | None = None) -> Any: ...
1816

19-
def get_config(self) -> CodecJSON_V2[str]: ...
17+
def get_config(self) -> Any: ...
2018

2119
@classmethod
22-
def from_config(cls, config: CodecJSON_V2[str]) -> Self: ...
20+
def from_config(cls, config: Any) -> Self: ...
2321

2422

2523
def _is_numcodec_cls(obj: object) -> TypeGuard[type[Numcodec]]:

src/zarr/codecs/_v2.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ async def _decode_single(
3131
cdata = chunk_bytes.as_array_like()
3232
# decompress
3333
if self.compressor:
34-
chunk = await asyncio.to_thread(self.compressor.decode, cdata) # type: ignore[arg-type]
34+
chunk = await asyncio.to_thread(self.compressor.decode, cdata)
3535
else:
36-
chunk = cdata # type: ignore[assignment]
36+
chunk = cdata
3737

3838
# apply filters
3939
if self.filters:
@@ -54,7 +54,7 @@ async def _decode_single(
5454
# is an object array. In this case, we need to convert the object
5555
# array to the correct dtype.
5656

57-
chunk = np.array(chunk).astype(chunk_spec.dtype.to_native_dtype()) # type: ignore[assignment]
57+
chunk = np.array(chunk).astype(chunk_spec.dtype.to_native_dtype())
5858

5959
elif chunk.dtype != object:
6060
# If we end up here, someone must have hacked around with the filters.
@@ -83,18 +83,16 @@ async def _encode_single(
8383
# apply filters
8484
if self.filters:
8585
for f in self.filters:
86-
chunk = await asyncio.to_thread(f.encode, chunk) # type: ignore[arg-type]
87-
86+
chunk = await asyncio.to_thread(f.encode, chunk)
8887
# check object encoding
8988
if ensure_ndarray_like(chunk).dtype == object:
9089
raise RuntimeError("cannot write object array without object codec")
9190

9291
# compress
9392
if self.compressor:
94-
cdata = await asyncio.to_thread(self.compressor.encode, chunk) # type: ignore[arg-type]
93+
cdata = await asyncio.to_thread(self.compressor.encode, chunk)
9594
else:
96-
cdata = chunk # type: ignore[assignment]
97-
95+
cdata = chunk
9896
cdata = ensure_bytes(cdata)
9997
return chunk_spec.prototype.buffer.from_bytes(cdata)
10098

src/zarr/core/array.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4849,12 +4849,12 @@ def _parse_chunk_encoding_v2(
48494849
if _compressor is None:
48504850
object_codec_id = None
48514851
else:
4852-
object_codec_id = get_object_codec_id((_compressor.get_config(),)) # type: ignore[arg-type]
4852+
object_codec_id = get_object_codec_id((_compressor.get_config(),))
48534853
else:
48544854
object_codec_id = get_object_codec_id(
48554855
(
4856-
*[f.get_config() for f in _filters], # type: ignore[arg-type]
4857-
_compressor.get_config() if _compressor is not None else None, # type: ignore[arg-type]
4856+
*[f.get_config() for f in _filters],
4857+
_compressor.get_config() if _compressor is not None else None,
48584858
)
48594859
)
48604860
if object_codec_id is None:

src/zarr/core/metadata/v2.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,8 @@ def to_dict(self) -> dict[str, JSON]:
200200
codec_config = zarray_dict["compressor"].get_config()
201201
# Hotfix for https://github.com/zarr-developers/zarr-python/issues/2647
202202
if codec_config["id"] == "zstd" and not codec_config.get("checksum", False):
203-
codec_config.pop("checksum") # type: ignore[typeddict-item]
204-
zarray_dict["compressor"] = codec_config # type: ignore[assignment]
203+
codec_config.pop("checksum")
204+
zarray_dict["compressor"] = codec_config
205205

206206
if zarray_dict["filters"] is not None:
207207
raw_filters = zarray_dict["filters"]
@@ -215,7 +215,7 @@ def to_dict(self) -> dict[str, JSON]:
215215
new_filters.append(f.get_config())
216216
else:
217217
new_filters.append(f)
218-
zarray_dict["filters"] = new_filters # type: ignore[assignment]
218+
zarray_dict["filters"] = new_filters
219219

220220
# serialize the fill value after dtype-specific JSON encoding
221221
if self.fill_value is not None:

0 commit comments

Comments
 (0)