|
31 | 31 |
|
32 | 32 | if TYPE_CHECKING: |
33 | 33 | from zarr_metadata._common import JSONValue |
| 34 | + from zarr_metadata.model._array import ZarrV2AttributesStoreKey |
34 | 35 | from zarr_metadata.v2.group import ZarrV2GroupMetadataJSON |
35 | 36 | from zarr_metadata.v3.array import ZarrV3ExtensionField |
36 | 37 | from zarr_metadata.v3.consolidated import ZarrV3ConsolidatedMetadataJSON |
@@ -186,7 +187,9 @@ def must_understand_fields(self) -> dict[str, ZarrV3ExtensionField]: |
186 | 187 | def from_key_value(cls, mapping: Mapping[str, bytes]) -> ZarrV3GroupMetadata: |
187 | 188 | return cls.from_json(load_store_json(mapping, GROUP_METADATA_STORE_KEY_V3)) |
188 | 189 |
|
189 | | - def to_key_value(self, *, indent: int | str | None = None) -> Mapping[str, bytes]: |
| 190 | + def to_key_value( |
| 191 | + self, *, indent: int | str | None = None |
| 192 | + ) -> Mapping[ZarrV3GroupMetadataStoreKey, bytes]: |
190 | 193 | return {GROUP_METADATA_STORE_KEY_V3: dump_store_json(self.to_json(), indent=indent)} |
191 | 194 |
|
192 | 195 |
|
@@ -338,12 +341,16 @@ def from_key_value(cls, mapping: Mapping[str, bytes]) -> ZarrV2GroupMetadata: |
338 | 341 | return cls.from_json({**zgroup, "attributes": zattrs}) |
339 | 342 | return cls.from_json(zgroup) |
340 | 343 |
|
341 | | - def to_key_value(self, *, indent: int | str | None = None) -> Mapping[str, bytes]: |
| 344 | + def to_key_value( |
| 345 | + self, *, indent: int | str | None = None |
| 346 | + ) -> Mapping[ZarrV2GroupMetadataStoreKey | ZarrV2AttributesStoreKey, bytes]: |
342 | 347 | # Attributes live only in the sibling `.zattrs` file; the `.zgroup` |
343 | 348 | # document must exclude them. The `.zattrs` key is present exactly |
344 | 349 | # when attributes are set (even empty) — UNSET emits no file. |
345 | 350 | zgroup = {k: v for k, v in self.to_json().items() if k != "attributes"} |
346 | | - out = {GROUP_METADATA_STORE_KEY_V2: dump_store_json(zgroup, indent=indent)} |
| 351 | + out: dict[ZarrV2GroupMetadataStoreKey | ZarrV2AttributesStoreKey, bytes] = { |
| 352 | + GROUP_METADATA_STORE_KEY_V2: dump_store_json(zgroup, indent=indent) |
| 353 | + } |
347 | 354 | if self.attributes is not UNSET: |
348 | 355 | out[ATTRIBUTES_STORE_KEY_V2] = dump_store_json(self.attributes, indent=indent) |
349 | 356 | return out |
@@ -429,5 +436,7 @@ def from_json(cls, data: object) -> ZarrV2ConsolidatedMetadata: |
429 | 436 | def from_key_value(cls, mapping: Mapping[str, bytes]) -> ZarrV2ConsolidatedMetadata: |
430 | 437 | return cls.from_json(load_store_json(mapping, CONSOLIDATED_METADATA_STORE_KEY_V2)) |
431 | 438 |
|
432 | | - def to_key_value(self, *, indent: int | str | None = None) -> Mapping[str, bytes]: |
| 439 | + def to_key_value( |
| 440 | + self, *, indent: int | str | None = None |
| 441 | + ) -> Mapping[ZarrV2ConsolidatedMetadataStoreKey, bytes]: |
433 | 442 | return {CONSOLIDATED_METADATA_STORE_KEY_V2: dump_store_json(self.to_json(), indent=indent)} |
0 commit comments