Skip to content

fix![zarr-metadata]: define JSONValue type, and narrow object annotations to use JSONValue#4037

Open
d-v-b wants to merge 6 commits into
zarr-developers:mainfrom
d-v-b:json-in-zarr-metadata
Open

fix![zarr-metadata]: define JSONValue type, and narrow object annotations to use JSONValue#4037
d-v-b wants to merge 6 commits into
zarr-developers:mainfrom
d-v-b:json-in-zarr-metadata

Conversation

@d-v-b
Copy link
Copy Markdown
Contributor

@d-v-b d-v-b commented Jun 4, 2026

This defines a JSONValue type that models python objects that easily become JSON. To be clear, json.loads is still essentially untyped, so this JSONValue type 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. the fill_value field of array metadata documents, which previously were object, and that's far too open.

Happy to be bikeshedded on the name of the type -- JSON or JSONValue. I think JSONValue is more accurate, since JSON can 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.

@github-actions github-actions Bot added the needs release notes Automatically applied to PRs which haven't added release notes label Jun 4, 2026
@d-v-b d-v-b requested a review from mkitti June 4, 2026 16:28
@mkitti mkitti requested a review from Copilot June 5, 2026 20:28
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 of object.
  • Narrow several schema fields to domain-specific types (e.g., StructField.data_type -> MetadataFieldV3).
  • Add a .claude hook 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.

Comment thread packages/zarr-metadata/src/zarr_metadata/_common.py
Comment thread packages/zarr-metadata/src/zarr_metadata/_common.py
d-v-b and others added 2 commits June 5, 2026 22:36
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs release notes Automatically applied to PRs which haven't added release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants