Repository navigation
feat(zarr-metadata): export the v3 node types, spec default separators and narrowing helpers - #4638
Merged
d-v-b merged 3 commits intoNov 16, 2026
Conversation
…s and narrowing helpers Add `ZarrV3NodeType` and `ZARR_V3_NODE_TYPE`; the default separators `ZARR_V2_ARRAY_DEFAULT_DIMENSION_SEPARATOR`, `DEFAULT_CHUNK_KEY_ENCODING_DEFAULT_SEPARATOR` and `V2_CHUNK_KEY_ENCODING_DEFAULT_SEPARATOR`; and the `TypeIs` helpers `is_zarr_v2_array_order`, `is_zarr_v2_array_dimension_separator` and `is_zarr_v3_node_type`. The v2 array reader, the v3 node reader and the chunk key encodings' canonicalization now use them in place of their own literals, which removes two casts from the v2 array reader. Assisted-by: ClaudeCode:claude-opus-5-5
Assisted-by: ClaudeCode:claude-opus-5-5
Assisted-by: ClaudeCode:claude-opus-5-5
Documentation build overview
|
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.
Export more constants, and define useful public type narrowing routines
🤖 AI text below 🤖
Adds
ZarrV3NodeTypeandZARR_V3_NODE_TYPE, and constants for the separators the spec assumes when one is absent (ZARR_V2_ARRAY_DEFAULT_DIMENSION_SEPARATOR,DEFAULT_CHUNK_KEY_ENCODING_DEFAULT_SEPARATOR,V2_CHUNK_KEY_ENCODING_DEFAULT_SEPARATOR). AddsTypeIshelpers that narrow anobjectto a spec value set:is_zarr_v2_array_order,is_zarr_v2_array_dimension_separatorandis_zarr_v3_node_type.Why
pydantic-zarr hardcodes these spec values or re-derives them (
get_args(MemoryOrder)followed bycast,node_type == "array" or node_type == "group", a hardcoded"."default). It should import them from zarr-metadata instead.The agent checked whether a tuple constant alone is enough, using
x in ZARR_V2_ARRAY_ORDERwithx: object:xto the Literal; mypy and ty do not.is_one_of(value, allowed: tuple[T, ...]) -> TypeIs[T]widensTtostrunder pyright and mypy.So each value set gets its own helper.
What changed
zarr_metadata.v2.array:ZARR_V2_ARRAY_DEFAULT_DIMENSION_SEPARATOR,is_zarr_v2_array_order,is_zarr_v2_array_dimension_separator.zarr_metadata.v3(home: the private modulev3/_common.py):ZarrV3NodeType(an alias of the format-neutral_hierarchy.NodeType),ZARR_V3_NODE_TYPE,is_zarr_v3_node_type.zarr_metadata.v3.chunk_key_encoding.{default,v2}:DEFAULT_CHUNK_KEY_ENCODING_DEFAULT_SEPARATOR("/") andV2_CHUNK_KEY_ENCODING_DEFAULT_SEPARATOR("."), each citing the spec line.zarr_metadataexports the constants and types. The helpers stay in their home modules, likeis_node_name_v3.("C", "F"),(".", "/"), its"."default and twocastcalls._NODE_TYPESand now returnsZarrV3NodeType | Noneinstead ofstr | None._canonicalcompares against its default constant.Considered and left out
FloatSpecialFillValue/FLOAT_SPECIAL_FILL_VALUESexport. It would need a single public home, and putting it in the float modules makes it value-tied withFloat{16,32,64}SpecialFillValue. Those per-width aliases are already public.ZarrV3GroupMetadataJSON.__required_keys__ | __optional_keys__already gives them at runtime.Tests
tests/test_spec_values.py: one parametrized test of the three helpers over members and non-members; one test that the v2 array model reads an absentdimension_separatoras the default; one test that each chunk key encoding's simplest spelling drops its default separator.test_public_api.py: the new front-door names, and theZARR_V3_NODE_TYPE/ZarrV3NodeTypedrift pair.mkdocs build --strictprinted no warnings.🤖 Generated with Claude Code