Skip to content

fix(zarr-indexing): replace runtime assert statements with explicit checks - #4364

Merged
d-v-b merged 1 commit into
zarr-developers:mainfrom
d-v-b:claude/nostalgic-feynman-1c2cfa
Sep 16, 2026
Merged

d-v-b merged 1 commit into
zarr-developers:mainfrom
d-v-b:claude/nostalgic-feynman-1c2cfa

Conversation

@d-v-b

@d-v-b d-v-b commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

AI-authored PR that cleans out runtime asserts from zarr-indexing.

🤖 AI text below 🤖

Follow-up to #4363, which enabled ruff's S101 (no assert in runtime code) repo-wide but left a temporary exemption for packages/zarr-indexing/src/**. This removes the sixteen asserts that exemption covered and drops the exemption.

Same treatment as #4363:

  • Restructured so mypy narrows without them (13 sites). IndexTransform.inverse validates and builds in one loop, so the ArrayMap rejection narrows the map type directly. The correlated-block mask in _intersect_general starts as an all-true array instead of None. The general and orthogonal lowering paths in reader.py branch on isinstance rather than on membership in a dims list and carry the ArrayMaps in a paired list. _apply_vindex keeps its slices in a typed dict. _write_affine moves the ArrayMap check into the loop as an early return False. _resolve_upper_bound tests the raw list instead of the field name.
  • Converted to RuntimeError (3 sites). _indexed_set raises if an orthogonal map has no dependent axis, which index_array_structure routes to the general path before it can get there. A _finite helper in messages.py replaces the three post-validation isinstance(value, int) asserts.

None of the new raises is reachable through the public API, so no new tests; the existing suite exercises every restructured path. zarr_indexing/testing/ is untouched (covered by the **/testing/** ignore).

Verified: ruff check ., ruff check packages/zarr-indexing/src --select S101 --ignore-noqa, root mypy, the package's pyright recipe (no new warnings), and the zarr-indexing suite (1739 passed).

🤖 Generated with Claude Code

…hecks

Asserts are stripped under `python -O`. The sixteen in zarr-indexing's
runtime code narrowed types or guarded internal invariants rather than
validating input, so most are restructured away: `inverse` validates
and builds in one pass, the correlated-block mask starts all-true
instead of `None`, the lowering paths branch on the map type instead
of on membership in a dims list, the vindex path keeps its slices in a
typed dict, and the affine writer returns early on an index array. The
remainder become `RuntimeError`s for states the public API cannot
reach, via a `_finite` helper in the message layer and an explicit
check in `_indexed_set`.

The `packages/zarr-indexing/src/**` exemption from ruff's S101 rule is
removed so the package is held to the same standard as `src/zarr`.

Assisted-by: ClaudeCode:claude-fable-5-1
@d-v-b
d-v-b force-pushed the claude/nostalgic-feynman-1c2cfa branch from 37ff3c9 to 0172612 Compare September 16, 2026 11:41
@github-actions github-actions Bot added the needs release notes Automatically applied to PRs which haven't added release notes label Sep 16, 2026
@read-the-docs-community

Copy link
Copy Markdown

Documentation build overview

📚 zarr-indexing | 🛠️ Build #34589702 | 📁 Comparing 0172612 against latest (9f0ae4e)

  🔍 Preview build  

1 file changed
± api/transform/index.html

@d-v-b
d-v-b marked this pull request as ready for review September 16, 2026 11:51
@d-v-b
d-v-b merged commit dfa18e8 into zarr-developers:main Sep 16, 2026
39 checks passed
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.

1 participant