|
16 | 16 | MetadataValidationError, |
17 | 17 | StoreKey, |
18 | 18 | ValidationProblem, |
19 | | - arrays_to_tuples, |
20 | 19 | dump_store_json, |
21 | 20 | load_store_json, |
22 | 21 | parse_array_metadata_v2, |
@@ -79,12 +78,8 @@ def from_json(cls, data: object) -> ZarrV3NamedConfig: |
79 | 78 | field = parse_metadata_field_v3(data) |
80 | 79 | if isinstance(field, str): |
81 | 80 | return cls(name=field, configuration={}, must_understand=True) |
82 | | - # Sound cast: parse_metadata_field_v3 checked the configuration is a |
83 | | - # string-keyed mapping of JSON values; arrays_to_tuples only converts |
84 | | - # lists to tuples within that shape. |
85 | | - configuration = cast( |
86 | | - "dict[str, JSONValue]", arrays_to_tuples(dict(field.get("configuration", {}))) |
87 | | - ) |
| 81 | + # A read model shares no mutable state with what it read. |
| 82 | + configuration = copy.deepcopy(dict(field.get("configuration", {}))) |
88 | 83 | return cls( |
89 | 84 | name=field["name"], |
90 | 85 | configuration=configuration, |
@@ -287,7 +282,8 @@ def to_json(self) -> ZarrV3ArrayMetadataJSON: |
287 | 282 |
|
288 | 283 | @classmethod |
289 | 284 | def from_json(cls, data: object) -> ZarrV3ArrayMetadata: |
290 | | - parsed = parse_array_metadata_v3(arrays_to_tuples(data)) |
| 285 | + # A read model shares no mutable state with what it read. |
| 286 | + parsed = copy.deepcopy(parse_array_metadata_v3(data)) |
291 | 287 | # Sound cast: the TypedDict types all non-standard keys as its |
292 | 288 | # `extra_items` (`ZarrV3ExtensionField`); the comprehension's inferred value |
293 | 289 | # type is the union over ALL keys because the key filter cannot narrow it. |
@@ -458,7 +454,8 @@ def to_json(self) -> ZarrV2ArrayMetadataJSON: |
458 | 454 |
|
459 | 455 | @classmethod |
460 | 456 | def from_json(cls, data: object) -> ZarrV2ArrayMetadata: |
461 | | - parsed = parse_array_metadata_v2(arrays_to_tuples(data)) |
| 457 | + # A read model shares no mutable state with what it read. |
| 458 | + parsed = copy.deepcopy(parse_array_metadata_v2(data)) |
462 | 459 | return cls( |
463 | 460 | shape=parsed["shape"], |
464 | 461 | dtype=parsed["dtype"], |
|
0 commit comments