@@ -261,7 +261,8 @@ def _json_convert(o: np.dtype[Any] | Enum | Codec) -> str | dict[str, Any]:
261
261
# this serializes numcodecs compressors
262
262
# todo: implement to_dict for codecs
263
263
elif isinstance (o , numcodecs .abc .Codec ):
264
- return o .get_config ()
264
+ config : dict [str , Any ] = o .get_config ()
265
+ return config
265
266
raise TypeError
266
267
267
268
return {
@@ -270,14 +271,14 @@ def _json_convert(o: np.dtype[Any] | Enum | Codec) -> str | dict[str, Any]:
270
271
271
272
@classmethod
272
273
def from_dict (cls , data : dict [str , JSON ]) -> ArrayV3Metadata :
274
+ # TODO: Remove the type: ignores[] comments below and use a TypedDict to type `data`
273
275
# check that the zarr_format attribute is correct
274
- _ = parse_zarr_format_v3 (data .pop ("zarr_format" ))
276
+ _ = parse_zarr_format_v3 (data .pop ("zarr_format" )) # type: ignore[arg-type]
275
277
# check that the node_type attribute is correct
276
- _ = parse_node_type_array (data .pop ("node_type" ))
278
+ _ = parse_node_type_array (data .pop ("node_type" )) # type: ignore[arg-type]
277
279
278
280
data ["dimension_names" ] = data .pop ("dimension_names" , None )
279
281
280
- # TODO: Remove the ignores and use a TypedDict to type `data`
281
282
return cls (** data ) # type: ignore[arg-type]
282
283
283
284
def to_dict (self ) -> dict [str , Any ]:
@@ -450,32 +451,32 @@ def parse_attributes(data: None | dict[str, JSON]) -> dict[str, JSON]:
450
451
# todo: move to its own module and drop _v3 suffix
451
452
# todo: consider folding all the literal parsing into a single function
452
453
# that takes 2 arguments
453
- def parse_zarr_format_v3 (data : Any ) -> Literal [3 ]:
454
+ def parse_zarr_format_v3 (data : Literal [ 3 ] ) -> Literal [3 ]:
454
455
if data == 3 :
455
456
return data
456
457
raise ValueError (f"Invalid value. Expected 3. Got { data } ." )
457
458
458
459
459
460
# todo: move to its own module and drop _v2 suffix
460
- def parse_zarr_format_v2 (data : Any ) -> Literal [2 ]:
461
+ def parse_zarr_format_v2 (data : Literal [ 2 ] ) -> Literal [2 ]:
461
462
if data == 2 :
462
463
return data
463
464
raise ValueError (f"Invalid value. Expected 2. Got { data } ." )
464
465
465
466
466
- def parse_node_type_array (data : Any ) -> Literal ["array" ]:
467
+ def parse_node_type_array (data : Literal [ "array" ] ) -> Literal ["array" ]:
467
468
if data == "array" :
468
469
return data
469
470
raise ValueError (f"Invalid value. Expected 'array'. Got { data } ." )
470
471
471
472
472
473
# todo: real validation
473
- def parse_filters (data : Any ) -> list [dict [str , JSON ]]:
474
+ def parse_filters (data : list [ dict [ str , JSON ]] | None ) -> list [dict [str , JSON ]] | None :
474
475
return data
475
476
476
477
477
478
# todo: real validation
478
- def parse_compressor (data : Any ) -> dict [str , JSON ] | None :
479
+ def parse_compressor (data : dict [ str , JSON ] | None ) -> dict [str , JSON ] | None :
479
480
return data
480
481
481
482
0 commit comments