@@ -34,7 +34,7 @@ def parse_codec_configuration(data: dict[str, JSON], expected_name_prefix: str)
3434 if not parsed_name .startswith (expected_name_prefix ):
3535 raise ValueError (
3636 f"Expected name to start with '{ expected_name_prefix } '. Got { parsed_name } instead."
37- )
37+ ) # pragma: no cover
3838 id = parsed_name [slice (len (expected_name_prefix ), None )]
3939 return {"id" : id , ** parsed_configuration }
4040
@@ -43,16 +43,22 @@ def parse_codec_configuration(data: dict[str, JSON], expected_name_prefix: str)
4343class NumcodecsCodec :
4444 codec_config : dict [str , JSON ]
4545
46- def __init__ (self , * , codec_id : str | None = None , codec_config : dict [str , JSON ]) -> None :
46+ def __init__ (
47+ self , * , codec_id : str | None = None , codec_config : dict [str , JSON ] | None = None
48+ ) -> None :
49+ if codec_config is None :
50+ codec_config = {}
4751 if "id" not in codec_config :
4852 if not codec_id :
4953 raise ValueError (
5054 "The codec id needs to be supplied either through the id attribute "
5155 "of the codec_config or through the codec_id argument."
52- )
56+ ) # pragma: no cover
5357 codec_config = {"id" : codec_id , ** codec_config }
5458 elif codec_id and codec_config ["id" ] != codec_id :
55- raise ValueError (f"Codec id does not match { codec_id } . Got: { codec_config ['id' ]} ." )
59+ raise ValueError (
60+ f"Codec id does not match { codec_id } . Got: { codec_config ['id' ]} ."
61+ ) # pragma: no cover
5662
5763 object .__setattr__ (self , "codec_config" , codec_config )
5864 warn (
@@ -84,7 +90,7 @@ def compute_encoded_size(self, input_byte_length: int, chunk_spec: ArraySpec) ->
8490
8591
8692class NumcodecsBytesBytesCodec (NumcodecsCodec , BytesBytesCodec ):
87- def __init__ (self , * , codec_id : str , codec_config : dict [str , JSON ]) -> None :
93+ def __init__ (self , * , codec_id : str , codec_config : dict [str , JSON ] | None = None ) -> None :
8894 super ().__init__ (codec_id = codec_id , codec_config = codec_config )
8995
9096 async def _decode_single (self , chunk_bytes : Buffer , chunk_spec : ArraySpec ) -> Buffer :
@@ -141,8 +147,6 @@ def make_bytes_bytes_codec(codec_id: str, cls_name: str) -> type[NumcodecsBytesB
141147
142148 class _Codec (NumcodecsBytesBytesCodec ):
143149 def __init__ (self , codec_config : dict [str , JSON ] | None = None ) -> None :
144- if codec_config is None :
145- codec_config = {}
146150 super ().__init__ (codec_id = _codec_id , codec_config = codec_config )
147151
148152 _Codec .__name__ = cls_name
@@ -155,8 +159,6 @@ def make_array_array_codec(codec_id: str, cls_name: str) -> type[NumcodecsArrayA
155159
156160 class _Codec (NumcodecsArrayArrayCodec ):
157161 def __init__ (self , codec_config : dict [str , JSON ] | None = None ) -> None :
158- if codec_config is None :
159- codec_config = {}
160162 super ().__init__ (codec_id = _codec_id , codec_config = codec_config )
161163
162164 _Codec .__name__ = cls_name
@@ -169,8 +171,6 @@ def make_array_bytes_codec(codec_id: str, cls_name: str) -> type[NumcodecsArrayB
169171
170172 class _Codec (NumcodecsArrayBytesCodec ):
171173 def __init__ (self , codec_config : dict [str , JSON ] | None = None ) -> None :
172- if codec_config is None :
173- codec_config = {}
174174 super ().__init__ (codec_id = _codec_id , codec_config = codec_config )
175175
176176 _Codec .__name__ = cls_name
@@ -183,8 +183,6 @@ def make_checksum_codec(codec_id: str, cls_name: str) -> type[NumcodecsBytesByte
183183
184184 class _ChecksumCodec (NumcodecsBytesBytesCodec ):
185185 def __init__ (self , codec_config : dict [str , JSON ] | None = None ) -> None :
186- if codec_config is None :
187- codec_config = {}
188186 super ().__init__ (codec_id = _codec_id , codec_config = codec_config )
189187
190188 def compute_encoded_size (self , input_byte_length : int , chunk_spec : ArraySpec ) -> int :
0 commit comments