Skip to content

Commit 47d3316

Browse files
committed
chore: remove try_from_json method from protocol and arrayv3metadata
We couldn't agree on a name for `try_from_json`, and it's not an essential method, so I'm removing it for now. If we need this functionality on metadata objects we can always add it later.
1 parent 3423f39 commit 47d3316

3 files changed

Lines changed: 5 additions & 21 deletions

File tree

src/zarr/abc/serializable.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,6 @@ def from_json(cls, obj: T_contra) -> Self:
1212
"""
1313
...
1414

15-
@classmethod
16-
def try_from_json(cls, obj: object) -> Self:
17-
"""
18-
Deserialize from an unknown object. Details of any
19-
deserialization failure should be conveyed via an exception.
20-
"""
21-
...
22-
2315
def to_json(self) -> T_co:
2416
"""
2517
Serialize to JSON.

src/zarr/core/metadata/v3.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -593,15 +593,6 @@ def from_json(cls, obj: ArrayMetadataJSONLike_V3) -> Self:
593593
extra_fields=extra_fields or None, # type: ignore[arg-type]
594594
)
595595

596-
@classmethod
597-
def try_from_json(cls, obj: object) -> Self:
598-
"""
599-
Construct from an untrusted input (e.g. JSON read from disk).
600-
Validates the structure and raises a ``MetadataValidationError``
601-
listing all problems found.
602-
"""
603-
return cls.from_json(narrow_array_metadata_json(obj))
604-
605596
def update_shape(self, shape: tuple[int, ...]) -> Self:
606597
return replace(self, shape=shape)
607598

tests/test_metadata/test_v3.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
ArrayMetadataJSON_V3,
2323
ArrayV3Metadata,
2424
ChunkGridLike,
25+
narrow_array_metadata_json,
2526
parse_codecs,
2627
parse_dimension_names,
2728
parse_zarr_format,
@@ -569,8 +570,8 @@ def test_from_json(
569570
assert result.dimension_names == dimension_names.expected
570571
assert result.extra_fields == extra_fields.expected
571572

572-
# try_from_json should produce the same result for the same input
573-
assert ArrayV3Metadata.try_from_json(data) == result
573+
# narrow + from_json should produce the same result for the same input
574+
assert ArrayV3Metadata.from_json(narrow_array_metadata_json(data)) == result
574575

575576

576577
_VALID_TRY_FROM_JSON_INPUT: dict[str, object] = {
@@ -599,6 +600,6 @@ def test_from_json(
599600
({**_VALID_TRY_FROM_JSON_INPUT, "unknown_field": "value"}, "Disallowed extra fields"),
600601
],
601602
)
602-
def test_try_from_json_invalid(data: object, error_match: str) -> None:
603+
def test_narrow_array_metadata_json_invalid(data: object, error_match: str) -> None:
603604
with pytest.raises(MetadataValidationError, match=error_match):
604-
ArrayV3Metadata.try_from_json(data)
605+
narrow_array_metadata_json(data)

0 commit comments

Comments
 (0)