2727import asyncio
2828import math
2929from dataclasses import dataclass , replace
30- from functools import cached_property
3130from typing import (
3231 TYPE_CHECKING ,
3332 Any ,
8382
8483# Configuration classes for codec parameters
8584class LZ4Config (TypedDict ):
86- acceleration : NotRequired [ int ]
85+ acceleration : int
8786
8887
8988class ZlibConfig (TypedDict ):
90- level : NotRequired [ int ]
89+ level : int
9190
9291
9392class BZ2Config (TypedDict ):
94- level : NotRequired [ int ]
93+ level : int
9594
9695
9796class LZMAConfig (TypedDict ):
98- format : NotRequired [ int ]
99- check : NotRequired [ int ]
100- preset : NotRequired [ int ]
101- filters : NotRequired [ list [dict [str , Any ]]]
97+ format : int
98+ check : int
99+ preset : int | None
100+ filters : list [dict [str , Any ]] | None
102101
103102
104103class ShuffleConfig (TypedDict ):
105- elementsize : NotRequired [ int ]
104+ elementsize : int
106105
107106
108107class LZ4JSON_V2 (LZ4Config ):
@@ -158,7 +157,7 @@ class ShuffleJSON_V3(NamedRequiredConfig[Literal["shuffle"], ShuffleConfig]):
158157# Array-to-array codec configuration classes
159158class DeltaConfig (TypedDict ):
160159 dtype : str
161- astype : NotRequired [ str ]
160+ astype : str
162161
163162
164163class BitRoundConfig (TypedDict ):
@@ -183,7 +182,7 @@ class PackBitsConfig(TypedDict):
183182
184183class AsTypeConfig (TypedDict ):
185184 encode_dtype : str
186- decode_dtype : NotRequired [ str ]
185+ decode_dtype : str
187186
188187
189188# Array-to-array codec JSON representations
@@ -364,18 +363,16 @@ def _warn_unstable_specification(obj: _NumcodecsCodec) -> None:
364363class _NumcodecsCodec :
365364 codec_name : str
366365 _codec_id : ClassVar [str ]
366+ _codec : Numcodec
367367 codec_config : Mapping [str , Any ]
368368
369369 def __init__ (self , ** codec_config : Any ) -> None :
370- object .__setattr__ (self , "codec_config" , codec_config )
370+ object .__setattr__ (self , "_codec" , get_numcodec ({"id" : self ._codec_id , ** codec_config })) # type: ignore[typeddict-item]
371+ object .__setattr__ (self , "codec_config" , self ._codec .get_config ())
371372
372373 def to_dict (self ) -> dict [str , JSON ]:
373374 return cast (dict [str , JSON ], self .to_json (zarr_format = 3 ))
374375
375- @cached_property
376- def _codec (self ) -> Numcodec :
377- return get_numcodec ({"id" : self ._codec_id , ** self .codec_config }) # type: ignore[typeddict-item]
378-
379376 @classmethod
380377 def _from_json_v2 (cls , data : CodecJSON_V2 ) -> Self :
381378 return cls (** data )
0 commit comments