Repository navigation
refactor(zarr-metadata): type v3 node documents by their TypedDict before reading them in a scope - #493
Draft
d-v-b wants to merge 27 commits into
Draft
refactor(zarr-metadata): type v3 node documents by their TypedDict before reading them in a scope#493d-v-b wants to merge 27 commits into
d-v-b wants to merge 27 commits into
Conversation
…fore reading them in a scope
The v3 array and group readers now read a document in two steps. First
`typed_document` checks each member against its annotation in the node's
TypedDict, refining it once; then the semantic layer resolves each
declaration in the scope and checks members against each other (fill
value against data type, grid against shape, the codec pipeline,
dimension names against shape). The hand-written checks that restated the
annotations (`check_literal`, `dimension_lengths`, `attributes_of`, the
inline `dimension_names` checks, `members_past_the_levels`) are gone from
the v3 readers.
`attributes` and unclaimed extra fields are annotated `UserJSONValue`, so
the annotation decides where a non-finite number may be. Problems are now
located at the bad entry (`("shape", 1)` rather than `("shape",)`), and
reported in document order.
Assisted-by: ClaudeCode:claude-opus-5-5
…m its TypedDict `envelope_problems` now parses a declaration as `str | ZarrV3NamedConfigJSON` and adds only what the annotation cannot say: the extension-name syntax, and `must_understand: false` where a reader must understand the declaration. Configuration values are passed on unread, so the envelope check still walks only the envelope. Assisted-by: ClaudeCode:claude-opus-5-5
… keep claimed extension fields The type layer from 5f94a6a refined a member whole before typing it, so a member holding a declaration that was not JSON lost its other problems, and a claimed extension field was refined by the type layer instead of by the definition that claims it. Now: - a member that holds a declaration is parsed as written, and each declaration is refined where it sits (`_FindingDeclaration`), so a declaration that is not JSON is refused by its kind without hiding problems elsewhere in the member; - other members are refined once, by `refine_json`, or by `refine_user_data` when annotated `UserJSONValue`, then typed; - a member the TypedDict does not declare is passed on as written to `read_extra_fields_v3`, which refines it by the claiming definition; - only members that can hold a declaration are walked again to collect and swap out declarations, so large attributes are not copied. Problem order is: the type layer (missing keys, non-string keys, member types), then extension fields, then declarations, then the cross-member checks (fill value, grid lengths, pipeline, dimension names). Removes the now unused `holds`, `_GROUP_METADATA_REQUIRED_KEYS_V3` and the hand-written v3 member constants. Assisted-by: ClaudeCode:claude-opus-5-5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…typed_document cannot read A member that holds a declaration is parsed as written, and only its declarations, JSON values and user data are refined where they sit; the member itself is made a tuple when it is another kind of array. Any other leaf (a scalar, a nested array) would have read a value that was never refined, so compiling such a member now raises `TypeError`. So does a declaration of a kind that refines its declarations its own way, which removes the unreachable `resolve` branch of `read_found`, and an open TypedDict whose other keys may hold anything but user data, since `typed_document` passes those on as written. `_collect` and `_putting_back` now take the declaration type, so the walk over a checker's `_NestedDeclaration`s and over `typed_document`'s `FoundDeclaration`s is one walk. Adds tests/model/test_typed_document.py: one test that every problem in a document is reported (a non-JSON codec beside a bad one, NaN and nesting past the levels in separate codecs, a claimed extension field), which fails before 3ddee67, and one test for each compile-time error. Assisted-by: ClaudeCode:claude-opus-5-5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nfiguration key Assisted-by: ClaudeCode:claude-opus-5-5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ents first Assisted-by: ClaudeCode:claude-opus-5-5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…and type documents with it The checker in `_typed_json` assumed refined JSON, so reading a v3 node document needed a parallel member-by-member refine around it (the `_MemberLeaf` probe compile, `_Refining`, `_FindingDeclaration`, `FoundDeclaration`, `_Member`, `_MemberParsers`, and compile-time guards for the leaves that machinery could not refine). That duplicated the checker and `_NestedDeclaration`. Each parser now refines what it reads: a scalar or `Literal` reads a `StrEnum` or `IntEnum` member as its JSON, an array may be any sequence and a mapping any mapping, a number must be finite except under `UserJSONValue`, and a container must sit within `JSON_DEPTH` levels of the root, which `loc` locates it below. A value that is not JSON is reported where it sits; a container where a scalar is expected is reported once as the wrong type, as v2 documents already were. `typed_document` is now the document's TypedDict checker (`_checker`) plus the existing `_NestedDeclaration` walk, restricted to the members that can hold a declaration (`_declaring`) and typed cleanly. The declaration leaf refines each declaration where it sits and carries the declaration as written and every reason it is not JSON, which `read_found` hands to `resolve_refined`. `typed_json.check` no longer refines the whole value first, so it honors `UserJSONValue`. Assisted-by: ClaudeCode:claude-opus-5-5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…read them Review of e2eccca found the configuration path half migrated to the refining checker: - A nested declaration that is not JSON (a NaN in a codec held by a `finite=False` configuration) was read as null and reported as "got null" at the declaration. `_envelope` now reports why it is not JSON, and the configuration's nested-declaration loop refuses it through `resolve_refined`, as a document's declarations are; `_moved` locates the declaration and its problems together. - `typed_json.check` returned a value when a closed TypedDict's undeclared key held a value that is not JSON. `object_of` now refines that value as user data, so it is reported but may hold any number. - A declaration that writes no configuration at the last level a reader walks was refused, because the empty configuration made up for it was depth-checked. It is no longer checked: it is not in the input. A number that is not finite now stands only where the annotation is `UserJSONValue`, also in a `finite=False` configuration, whose `float` members accepted one before. The `finite` docstrings say so. Assisted-by: ClaudeCode:claude-opus-5-5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…th readers and refine undeclared values strictly A declaration that writes no configuration has the empty one, which is not in the input; `_read` and `_read_carried` now share `_given`, so neither counts it as a level (a carried data type such as `r16` at the last level was refused). A value under a key a TypedDict does not declare is refined by `refine_json`: no annotation says it may hold a number that is not finite, so `finite=False` no longer lets one through there. The unused `_checked` is removed. Assisted-by: ClaudeCode:claude-opus-5-5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ember holds `read_consolidated_metadata_v3` reported a member the envelope does not declare but did not refine its value, while the group reader, which types the same envelope with the checker, does. A value that is not JSON, or a number that is not finite, under such a member is now reported by both. The package docstring says an unknown key's value must still be JSON, and a test pins NaN under an undeclared key of a `finite=False` extension field. Assisted-by: ClaudeCode:claude-opus-5-5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e group uses `read_consolidated_metadata_v3` checked the envelope by hand, so it drifted from the group's extension field, which checks the same member by `ZarrV3ConsolidatedMetadataEnvelopeJSON`: it counted depth under an unexpected member one level short, ordered problems differently, and reported `kind: Infinity` as a wrong type. It now runs that checker, with the entries of `metadata` left out because each is read as a document, so both readers report the same problems in the same order. Assisted-by: ClaudeCode:claude-opus-5-5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…oblem in both readers Assisted-by: ClaudeCode:claude-opus-5-5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… the changelog entry Assisted-by: ClaudeCode:claude-opus-5-5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…of what a v3 declaration may hold `ExtraFieldDefinition.finite` is removed: a configuration says where a number that is not finite may stand by typing that member `UserJSONValue`. A v3 declaration is no longer refined strictly before it is read, a pass that stopped at the first value that was not JSON and so hid every other problem. Its kind refines it as user data only to build the JSON a reading holds (`UNSET` when it is not JSON). Then its envelope check, its definition's configuration check, or the kind's check of an unread configuration (`_unread`) each decide by annotation, on the declaration as written when it is not JSON. The same holds for nested declarations and for `read_configuration`. The envelope check passes the configuration on once it is an object, so its keys are checked once. An extension field's configuration keeps keys that are not strings, so its checker reports them. v2 kinds, whose envelopes are checked by hand, still refine strictly first. A refused declaration now holds what was written when it is JSON with any number, and a NaN in a nested codec refuses that codec, not the one that holds it. Assisted-by: ClaudeCode:claude-opus-5-5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ut saying why The envelope check counted depth from the declaration, so a container nested too deep under an envelope member it does not declare left the declaration's JSON unset with only an unknown key to explain it, and `read_configuration` put `None` where such a codec was. The envelope check now counts from the root, and a declaration whose JSON is unset is always reported with why it is not JSON (`_explained`, `_not_json`). A declaration holding a nested one that is not JSON, or whose number is not finite, is refused, so an accepted declaration always writes JSON. Its rules still run when every nested declaration has a name, read as written, so their problems are reported. A key that is not a string is reported with one message everywhere. Assisted-by: ClaudeCode:claude-opus-5-5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ations that are JSON A nested declaration that was not JSON was shown to the rules of the declaration holding it as null, so a rule that reads a nested codec's name failed. A nested declaration now counts as named only when it is JSON, as the rules contract says, and the holder's rules do not run otherwise. The two hand-written non-string key messages in model/_shared.py use the shared `non_string_key` problem. Assisted-by: ClaudeCode:claude-opus-5-5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… non-finite number The test for a nested declaration that is not JSON had a NaN case that passed whether or not the holder's rules ran. Split it: one test shows the rules skip a nested declaration of no JSON type, and one shows they still run, and report the codec beside it, when the nested declaration holds a non-finite number. Assisted-by: ClaudeCode:claude-opus-5-5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…mber to the JSON routines A number that is not finite is now JSON wherever the package reads one, as Python's `json` module reads and writes it. `refine_user_data`, the `UserJSONValue` alias and the `_user_json` checker leaf are removed, so a declaration, a configuration, attributes and an unclaimed member are all refined the same way. Where the spec gives a non-finite number a meaning, its own rule stays: a float fill value, or a complex component, that is a non-finite number is refused and must be written by its name. The rule now lives with the float fill value rules in both formats (`non_finite_fill_value`), and the `non_finite_fill_value` repair shares its naming (`non_finite_name`). An integer with more digits than the interpreter converts to text is still refused: without that guard, rule messages and `json_text`-based equality would raise on it, and `json.loads` never builds one. Assisted-by: ClaudeCode:claude-opus-5-5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ber needed `_pure` refused a declaration whose nested declaration held a non-finite number. A non-finite number is JSON now, and a nested declaration that is not JSON already leaves the declaration holding it without JSON, so it is refused through `json is UNSET`. Also from review round 4 of the rules gate: pin that a nested declaration whose configuration is not an object keeps its holder's rules from running, and say in the gate's comment and `_held`'s docstring that the rules see only nested declarations that are JSON. Assisted-by: ClaudeCode:claude-opus-5-5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… that JSON allows it Review round 1 of the non-finite change found stale text and test gaps: - docs/validation-rules.md still said `check` rejects a non-finite number everywhere. It now says a number may be non-finite anywhere except as a float fill value, and that a fill value of a data type nothing reads is not interpreted. The changelog fragment says so too. - The repair TypedDicts' docstrings no longer call a bare `NaN` "not JSON", or give `check` as the reason the fill value is not a member. - The message no longer says "fill value", since scale_offset and cast_value spell their scalars the same way. - The kept rule is pinned for float16, float64, both complex types and a struct float field, and an unread data type's fill value is pinned as free to hold any number. Assisted-by: ClaudeCode:claude-opus-5-5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ber may Address NaN review round 1 (crash lens): the pydantic warning, the writer and to_key_value docs no longer say non-finite numbers are kept to attributes; the definition docs warn that an unbounded float may be non-finite; the removals move to their own changelog fragment. Assisted-by: ClaudeCode:claude-opus-5-5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… refused as a non-finite number Address NaN review round 2 (no serious findings): - docs/validation-rules.md, the changelog and `non_finite_fill_value`'s docstring named only the fill value and complex components, while the rule also covers a struct's float field and codec scalars spelled as a fill value (`scale_offset`, `cast_value`). The docstring now states the rule once; the other texts follow it. - The definition docs said an unbounded `float` may be non-finite, which implied a bounded one is safe; a one-sided bound admits an infinity. - The removal fragment named the private `refine_user_data` and `refine_json`; it now gives the public removals and their migrations. - Minor wording in the attribute docstrings, the testing strategy, the repair docstring and the `typed_json` module docstring. Assisted-by: ClaudeCode:claude-opus-5-5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ers it writes by name `non_finite_name` and `non_finite_fill_value` decided, in the layer that knows no data type, how a non-finite number is written. The repair then chose which arrays to apply that to from a list of core type names and a prefix test on the name. Each float type now owns its names: the v3 float types and the v2 float and complex dtypes refuse a non-finite number with their own spec's spelling, and declare it with the new `fill_value_named` hook on `WithFillValue` (complex composes its component's). `named_fill_value` calls the hook for a data type a scope read. The `non_finite_fill_value` repair resolves the array's data type in the scope it is given, a new `context` argument on the repair functions that the repaired readers pass on, and writes what the type names. An extension data type that declares the hook is repaired too; one nothing in the scope reads is left for the strict read. Assisted-by: ClaudeCode:claude-opus-5-5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… names it, and nothing else Review round 1 of c27d46c: - The repair found names only in a scalar or a list, so an extension data type whose fill value is an object was never repaired, and `struct` declared no `fill_value_named`. The repair now walks lists and objects, and `struct` writes each field as that field's type does. - The repair wrote the hook's whole result while recording only some of its changes. It now writes only the non-finite numbers the hook gives a string for, and its message names the bare token it replaced. - The hook's contract is narrowed to non-finite numbers, which is all the repair writes. - Within each format, the float rule is built from the same function as the hook, so the two cannot drift apart. - docs/validation-rules.md no longer lists the float fill value rule among the rules that need no context; the `DataTypeDefinition` docstring and docs/extensions.md list the hook; the repair docstrings say they run the data type's code. Assisted-by: ClaudeCode:claude-opus-5-5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…value holding a non-finite number Review round 2: the repair ran an extension's `fill_value_named` on every listed array, so a hook that raised made the repaired reader fail on a document the strict reader accepts, which never runs the hook. The repair now first walks the fill value, with its own stack and to the reader's depth, and asks the data type only when it finds a non-finite number. docs/repair.md gives each format's default scope and says the v3 repair also writes a struct's float fields. Assisted-by: ClaudeCode:claude-opus-5-5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…fuse Review round 3: the pre-walk skipped the hook only for a fill value with no non-finite number, so a data type whose rules accept a bare `NaN` still had its `fill_value_named` run on a document whose read accepts it. The repair now checks the fill value against the data type's rules first, as reading the document does, and runs the hook only when they report a problem. The pre-walk is gone; the rules check costs more than it did on a large fill value (about 0.3 ms per listed array with a 1,024-element fill value), and nothing on a scalar one. Assisted-by: ClaudeCode:claude-opus-5-5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s it, and locate rule errors in a repair Review round 4 (no serious findings): - The struct hook named every non-finite field once any field was refused, including a field whose own type accepts a bare `NaN`. It now skips a field its type accepts. - An error raised by a data type's rules during a repair now names the listed entry it was reading. - The repair docstrings compared the repair with the group's strict read, which never reads the documents its consolidated metadata lists. They now compare it with reading those documents, which runs the same data type code. Assisted-by: ClaudeCode:claude-opus-5-5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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.
🤖 AI text below 🤖
Reading a v3 array or group document now checks each member against the document's TypedDict before any declaration is read, so a problem in one member no longer hides another, and a problem in
shapeordimension_namesis located at the element, such as('shape', 1). Nesting is counted from the root of the input, also in a consolidated listing. A non-finite number (NaN,Infinity,-Infinity) is now JSON everywhere: whether text may hold one is left to the routines that read and write it. A data type may still refuse a non-finite fill value that it writes by name, as the float types do in both formats, and it declares that spelling with the newfill_value_named.named_fill_valuecalls it, and the repair functions use it with a newcontextargument, so an extension data type takes part. A value that is not JSON no longer stops a declaration's own checks.typed_json.checkreturns each array as a tuple. Some problem messages, and their order, have changed.typed_json.UserJSONValueis removed: useJSONValue, which may now hold a non-finite number.ExtraFieldDefinition'sfiniteargument is removed: drop it, since every extension field may now hold one.Design
Reading a v3 node document is now a type refinement followed by semantic checks, instead of hand-written member checks (
members_past_the_levels,check_literal(doc, "zarr_format", 3), the_MEMBERS_V3tables).Refinement lives in the annotation checker. The parsers
_typed_jsoncompiles from a TypedDict refine raw input as they check it:bytes, a non-string key, an int too long to write as text);loc;JSONValueleaf refines withrefine_json;typed_json.checkno longer pre-refines the whole value, and neither does a definition'sread_configuration: thefiniteflag and the whole-configuration refine pass are gone.A non-finite number is JSON. Whether JSON text may hold
NaN,Infinityor-Infinityis left to the routines that read and write it (Python'sjsonmodule does both). The rules about a value's meaning stay: a value spelled as a float's fill value (the fill value, a complex component, a struct field, a codec scalar such asscale_offset'sscale) written as a non-finite number is refused because the spec says to write it by its name.refine_user_data,UserJSONValueand the purity gate on nested declarations (_pure) are removed. The integer digit limit stays, because past it rule messages andjson_text-based equality would raise.The data type owns the spelling. No code outside a data type knows how it writes a non-finite number.
WithFillValuegainsfill_value_named, andnamed_fill_value(data_type, value)calls it for a data type a scope read. The v3 float types and the v2 float and complex dtypes build their refusal and their hook from one function per format; complex composes its component's, andstructits fields'. Thenon_finite_fill_valuerepair resolves the array's data type in thecontextit is given (new keyword on the three repair functions, passed on by the repaired readers), runs the hook only for a fill value the data type's rules refuse, and writes only the non-finite numbers the hook gives a string for. This replaces a generic helper and a hard-coded list of core type names.typed_document(doc, shape, at)(definition/_definition.py) types the document with the same compiled checker (_checker) that reads configurations. The declaration leaf returns a_NestedDeclarationholding its refined JSON, what was written, and its refine problems. A declaration that is not JSON is therefore refused by its kind without hiding the member's other declarations. Undeclared string keys are passed on as extension fields to the claiming definition.read_array_v3/read_group_v3then read each nested declaration in the scope (read_found), the extension fields, and the cross-member checks (fill value against data type, grid against shape, the codec pipeline,dimension_nameslength).Configurations share the unwritten-configuration rule. A declaration that writes no configuration has the empty one, which is not in the input and is not depth-checked (
_given, shared by_readand_read_carried).One envelope rule.
read_consolidated_metadata_v3checks the envelope withtyped_json.checkagainstZarrV3ConsolidatedMetadataEnvelopeJSON, the same TypedDict the group's extension field uses. The entries ofmetadataare left out because each is read as a document.Envelope check derived. The declaration envelope check is derived from
str | ZarrV3NamedConfigJSON(definition/_envelope.py).An earlier version of this PR added a parallel set of member and leaf parsers (
FoundDeclaration,_MemberParsers,_Refining, compile-time guards). They duplicated the checker and are deleted. src is +427/−351 against 4b2dede.Behavior changes
shape/dimension_namespoint at the element.bytes) reports the non-JSON value only.NaN,Infinityor-Infinityanywhere, including in a configuration, a nested declaration, and an undeclared key. Previously onlyattributesand unclaimed extension fields could hold one.scale_offset/cast_valuescalars) written as a non-finite number is still refused, in v2 and v3.{"name": "float64"}) and any v2 float typestr the reader accepts (such as<f08), and works for an extension data type that declaresfill_value_named. A complex fill value with one component of the wrong type ([NaN, null]) is no longer partly repaired; the strict read refuses it either way. A fill value whose data type nothing in scope reads is not interpreted, so it may hold one.ExtraFieldDefinition(finite=...),refine_user_dataandtyped_json.UserJSONValueare removed.typed_json.checkreturns arrays as tuples.read_consolidated_metadata_v3reports the same envelope problems as the group reader, in the same order. Missing-key messages name the key, and depth counts from the group.codecs: []reports the genericMinLenmessage.additionalProperties(any JSON value) on the node documents and theirattributes.to_jsonoutput and declaration placement (106,398 differential runs against 4b2dede), apart from the non-finite change above and one exception. A v2 structured dtype nested 127 levels deep, whose innermost record has a subarray shape, is now refused as nested too deep (see the review record).Performance against 4b2dede (
read_array_metadata_v3, CPython 3.11 arm64):The non-finite change did not move these numbers (measured again at a3aa5e7).
Adversarial review record
Fresh reviewer agents were given the diff and files, not the author's conclusions. Each finding was reproduced before it was fixed, and each fix has a test that fails without it.
First design (5f94a6a–9553a2cc8):
Rework onto the checker (e2eccca–aec16c1d5):
finite=Falsesemantics left undecided; now decided by annotation, with docstrings updated.checkaccepted a non-JSON value under an undeclared key._given. A carried data type such asr16at the last level was refused. Test gaps were filled in the same commit.The gap noted after round 6 (the group reader stopping at the first non-JSON problem in an extension field) is closed by removing
finiteand the whole-value refine passes:Checker as the only refiner (1aa86a8–789f2e380):
read_configurationmixedNoneandUNSETfor "not JSON", and some docs were stale.TypeError. Rules now run only when every nested declaration is JSON.{"fields": records}, so the checker counts one level more than the document. A struct nested 127 levels deep with a subarray shape at the bottom (which NumPy can build) is refused. Base accepted it. A correct fix checks the records at their document location, which belongs with porting the v2 readers onto the chain (see follow-ups); threading a depth offset through every checker parser would be a larger change than the bug._named). The test was split in 5542559, and the mutant now fails it. Also noted, by design: a nested declaration of no JSON type suppresses the holder's rules, so a problem they would find in a sibling is not reported, as for a nested declaration with no name._held's docstring did not say the rules see only nested declarations that are JSON. Both fixed in 56561b5.Non-finite numbers are JSON (ddacc86, 56561b5), after the author decided that what counts as valid JSON is left to the JSON IO routines:
docs/validation-rules.mdstill saidcheckrejects a non-finite number everywhere; the repair TypedDicts called a bareNaN"not JSON"; the kept rule's message said "fill value" althoughscale_offsetandcast_valuespell scalars the same way; the rule was untested for float16, float64, both complex types and a struct field.to_key_valuedocstrings still said non-finite numbers are kept to attributes; the definition docs now warn that an unboundedfloatmay be non-finite; the removals moved to their own changelog fragment.UserJSONValuealias (the package is pre-1.0); spelling a non-finite fill value by name increate_default(not a regression).sys.get_int_max_str_digitscrash f-string rule messages andjson_text-based==andhash.scale_offset'sscaleandoffset,cast_value's fill value andscalar_map). The rule is now stated once, innon_finite_fill_value's docstring, and the other texts follow it.floatcannot be non-finite; a one-sided bound admits an infinity.refine_user_data,refine_json); it now lists the public removals with their migrations.typed_jsondocstring.The data type owns the spelling (c27d46c), after the author pointed out that a generic
non_finite_namecannot be judged outside a specific data type:structhad no hook. The repair now walks lists and objects andstructcomposes its fields. Also fixed there: the repair wrote changes it did not record (now it writes only the non-finite numbers), the hook's contract was wider than the repair (narrowed to non-finite numbers), the rule and hook could drift (one function per format), and stale docs (validation-rules, extensions,DataTypeDefinition). Declined: sharing the naming function between v2 and v3, since each spec spells the names itself.NaNstill had its hook run on a document the strict read accepts. The repair now runs the hook only when the data type's rules refuse the fill value, which makes "the repaired read never fails where the strict read accepts" hold by construction and removes the pre-walk (and its cost on large fill values).NaN(it now skips such a field); a rules error raised during a repair did not say which listed entry it was reading. Corrected in the docstrings and the 08d0cf7 message: the repair compares with reading the listed documents (read_consolidated_metadata_v3), not with the group read, which never reads them; and the rules check costs about 0.3 ms more per listed array with a large fill value, not less. The review stopped here: rounds 2 to 4 found nothing serious, and each later round found narrower extension-only edges.Process note: the late rounds kept finding the same kind of gap, a promise about the repair worded more broadly than the code. Stating each such invariant as a test before the change would have caught them in round 1.
Duplication audit of the type-checking path
After this PR, these routines still repeat work that the annotation checker does, or build the problems it builds:
_refinedrefines the whole declaration. When it is not JSON,_not_jsonrefines it again to explain why, and_unreadrefines the configuration once more. Then the checker walks the configuration. With one refiner and no purity gate this is now a cost, not a semantic risk: every pass usesrefine_json. The structural fix is to refine once, at the document location, with the checker's result as the declaration's JSON. That also removes the v2 struct depth exception, which comes from refining in configuration space (definition/_definition.py:316-341;v3/_definition.py:592-620repeats the trio for extension fields).model/_array_v2.py:213-334refines each member with its ownrefine_jsoncall.model/_group_v2.py:99-103,740-741usesmissing_keys,unexpected_keys,check_literalandvalidate_attributes. These are the member checks this PR removed for v3. Porting them ontotyped_documentdeletes most ofmodel/_shared.py:40-300.v2/_definition.py:221-233,316), while v3's is derived fromstr | ZarrV3NamedConfigJSON.model/_shared.py:44,58,model/_group_v3.py:892,model/_group_v2.py:731andv2/_definition.py:316. (The non-string key messages inmodel/_shared.pynow use the sharednon_string_keyproblem.)model/_group_v3.py:875-897,_node_type) checkszarr_formatandnode_typeby hand before typing. A union of the array and group TypedDicts would make it a checker call.model/_group_v3.py:1030,refine_json(document, at)), although the checker already counts depth from the root.Process suggestion: a test that fails when a
ValidationProblemwith kindmissing_keyorunknown_key, or a non-string key message, is built outside_typed_jsonand_json, with an allowlist for semantic rules (struct fields, blosctypesize). New readers would then reach for the checker instead of re-deriving its messages.Testing and follow-ups
typed_document. This also fixes the v2 struct depth exception above.RefusedDeclaration.🤖 Generated with Claude Code