Skip to content

Commit 0566131

Browse files
committed
Clarify ChunkKeyEncoding base class
- Enforce encode_chunk_key to be implemented (abstractmethod in ABC) - Make decode_chunk_key optional (raise NotImplementedError by default) Note, the latter is never raised by the current zarr implementation.
1 parent c4ce5df commit 0566131

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/zarr/core/chunk_key_encodings.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import annotations
22

3-
from abc import abstractmethod
3+
from abc import ABC, abstractmethod
44
from dataclasses import dataclass
55
from typing import TYPE_CHECKING, Literal, TypeAlias, TypedDict, cast
66

@@ -29,7 +29,7 @@ class ChunkKeyEncodingParams(TypedDict):
2929

3030

3131
@dataclass(frozen=True)
32-
class ChunkKeyEncoding(Metadata):
32+
class ChunkKeyEncoding(ABC, Metadata):
3333
name: str
3434
separator: SeparatorLiteral = "."
3535

@@ -45,13 +45,19 @@ def from_dict(cls, data: dict[str, JSON]) -> Self:
4545
def to_dict(self) -> dict[str, JSON]:
4646
return {"name": self.name, "configuration": {"separator": self.separator}}
4747

48-
@abstractmethod
4948
def decode_chunk_key(self, chunk_key: str) -> tuple[int, ...]:
50-
pass
49+
"""
50+
Optional: decode a chunk key string into chunk coordinates.
51+
Not required for normal operation; override if needed for testing or debugging.
52+
"""
53+
raise NotImplementedError(f"{self.__class__.__name__} does not implement decode_chunk_key.")
5154

5255
@abstractmethod
5356
def encode_chunk_key(self, chunk_coords: tuple[int, ...]) -> str:
54-
pass
57+
"""
58+
Encode chunk coordinates into a chunk key string.
59+
Must be implemented by subclasses.
60+
"""
5561

5662

5763
ChunkKeyEncodingLike: TypeAlias = dict[str, JSON] | ChunkKeyEncodingParams | ChunkKeyEncoding

src/zarr/registry.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ def register(self, cls: type[T], qualname: str | None = None) -> None:
6565
__ndbuffer_registry: Registry[NDBuffer] = Registry()
6666
__chunk_key_encoding_registry: Registry[ChunkKeyEncoding] = Registry()
6767

68-
# CHANGE: Consider updating docstring
6968
"""
7069
The registry module is responsible for managing implementations of codecs,
7170
pipelines, buffers, ndbuffers, and chunk key encodings and collecting them from entrypoints.

0 commit comments

Comments
 (0)