fix![zarr-metadata]: define JSONValue type, and narrow object annotations to use JSONValue#4037
Open
d-v-b wants to merge 6 commits into
Open
fix![zarr-metadata]: define JSONValue type, and narrow object annotations to use JSONValue#4037d-v-b wants to merge 6 commits into
d-v-b wants to merge 6 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR tightens the typing surface of zarr-metadata by introducing a recursive JSONValue type and using it to replace overly-broad object annotations in v2/v3 metadata TypedDicts (notably fill_value, attributes, and extension/configuration fields). It also narrows the struct field data_type to the existing MetadataFieldV3 union.
Changes:
- Add
JSONValue(recursive JSON-encodable value type) and apply it across v2/v3 metadata schemas in place ofobject. - Narrow several schema fields to domain-specific types (e.g.,
StructField.data_type -> MetadataFieldV3). - Add a
.claudehook log file to the repository (likely unintended for source control).
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/zarr-metadata/src/zarr_metadata/_common.py | Introduces JSONValue and uses it for NamedConfig.configuration. |
| packages/zarr-metadata/src/zarr_metadata/v3/array.py | Replaces object with JSONValue for fill_value, attributes, and v3 extension extra-items. |
| packages/zarr-metadata/src/zarr_metadata/v3/group.py | Narrows v3 group attributes to Mapping[str, JSONValue]. |
| packages/zarr-metadata/src/zarr_metadata/v3/data_type/struct.py | Narrows StructField.data_type to MetadataFieldV3 and StructFillValue to JSONValue. |
| packages/zarr-metadata/src/zarr_metadata/v3/codec/scale_offset.py | Narrows offset/scale config fields to JSONValue. |
| packages/zarr-metadata/src/zarr_metadata/v3/codec/cast_value.py | Narrows scalar_map entries to tuple[JSONValue, JSONValue]. |
| packages/zarr-metadata/src/zarr_metadata/v2/array.py | Narrows v2 array fill_value and merged attributes to JSONValue. |
| packages/zarr-metadata/src/zarr_metadata/v2/group.py | Narrows v2 group merged attributes to JSONValue. |
| packages/zarr-metadata/src/zarr_metadata/v2/codec.py | Narrows v2 codec extra-items to JSONValue. |
| packages/zarr-metadata/src/zarr_metadata/v2/attributes.py | Narrows .zattrs content to Mapping[str, JSONValue]. |
| packages/zarr-metadata/.claude/hooks/.logs/hook-log.jsonl | Adds a hook execution log entry to the repo. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This defines a
JSONValuetype that models python objects that easily become JSON. To be clear,json.loadsis still essentially untyped, so thisJSONValuetype requires type narrowing when you read actual JSON data. But for constructing values that will fit into JSON, this is a useful type and necessary for modelling e.g. thefill_valuefield of array metadata documents, which previously wereobject, and that's far too open.Happy to be bikeshedded on the name of the type --
JSONorJSONValue. I thinkJSONValueis more accurate, sinceJSONcan denote a file or a bytestream or the format.This is a breaking change to zarr-metadata, so it needs a minor version bump (e.g., to 0.3.0) when we issue our next release of the package.