@@ -30,20 +30,21 @@ class ChunkKeyEncodingParams(TypedDict):
3030
3131@dataclass (frozen = True )
3232class ChunkKeyEncoding (ABC , Metadata ):
33- name : ClassVar [ str ]
34- separator : SeparatorLiteral = "."
33+ """
34+ Defines how chunk coordinates are mapped to store keys.
3535
36- def __post_init__ (self ) -> None :
37- separator_parsed = parse_separator (self .separator )
38- object .__setattr__ (self , "separator" , separator_parsed )
36+ Subclasses must define a class variable `name` and implement `encode_chunk_key`.
37+ """
38+
39+ name : ClassVar [str ]
3940
4041 @classmethod
4142 def from_dict (cls , data : dict [str , JSON ]) -> Self :
42- name_parsed , config_parsed = parse_named_configuration (data , require_configuration = False )
43+ _ , config_parsed = parse_named_configuration (data , require_configuration = False )
4344 return cls (** config_parsed if config_parsed else {}) # type: ignore[arg-type]
4445
4546 def to_dict (self ) -> dict [str , JSON ]:
46- return {"name" : self .name , "configuration" : { "separator" : self . separator } }
47+ return {"name" : self .name , "configuration" : super (). to_dict () }
4748
4849 def decode_chunk_key (self , chunk_key : str ) -> tuple [int , ...]:
4950 """
@@ -66,7 +67,11 @@ def encode_chunk_key(self, chunk_coords: tuple[int, ...]) -> str:
6667@dataclass (frozen = True )
6768class DefaultChunkKeyEncoding (ChunkKeyEncoding ):
6869 name : ClassVar [Literal ["default" ]] = "default"
69- separator : SeparatorLiteral = "/" # default
70+ separator : SeparatorLiteral = "/"
71+
72+ def __post_init__ (self ) -> None :
73+ separator_parsed = parse_separator (self .separator )
74+ object .__setattr__ (self , "separator" , separator_parsed )
7075
7176 def decode_chunk_key (self , chunk_key : str ) -> tuple [int , ...]:
7277 if chunk_key == "c" :
@@ -80,7 +85,11 @@ def encode_chunk_key(self, chunk_coords: tuple[int, ...]) -> str:
8085@dataclass (frozen = True )
8186class V2ChunkKeyEncoding (ChunkKeyEncoding ):
8287 name : ClassVar [Literal ["v2" ]] = "v2"
83- separator : SeparatorLiteral = "." # default
88+ separator : SeparatorLiteral = "."
89+
90+ def __post_init__ (self ) -> None :
91+ separator_parsed = parse_separator (self .separator )
92+ object .__setattr__ (self , "separator" , separator_parsed )
8493
8594 def decode_chunk_key (self , chunk_key : str ) -> tuple [int , ...]:
8695 return tuple (map (int , chunk_key .split (self .separator )))
0 commit comments