fix(zarr-metadata)!: guards narrow only when they say yes - #4429
Merged
d-v-b merged 1 commit intoSep 26, 2026
Merged
Conversation
This was referenced Sep 26, 2026
d-v-b
force-pushed
the
fix/zarr-metadata-guards-typeguard
branch
from
September 26, 2026 17:45
a73b46a to
7917b97
Compare
Documentation build overview
|
d-v-b
force-pushed
the
fix/zarr-metadata-guards-typeguard
branch
2 times, most recently
from
September 26, 2026 18:41
b4dfa2d to
e48c105
Compare
d-v-b
marked this pull request as ready for review
September 26, 2026 18:46
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4429 +/- ##
===========================================
+ Coverage 52.54% 94.37% +41.83%
===========================================
Files 93 93
Lines 13174 13174
===========================================
+ Hits 6922 12433 +5511
+ Misses 6252 741 -5511 🚀 New features to boost your workflow:
|
`TypeIs[T]` promises True exactly for the values that are `T`, and type checkers narrow `T` away when it returns False. Every `is_*` guard is stricter than its type: `is_json(math.nan)` is False for a `float`, and the document guards are False for well-typed documents that break a structural rule. A consumer narrowing on the False branch type-checked and then failed at run time. The guards are now `TypeGuard`s, which narrow only on True. BREAKING CHANGE: code that relied on a False result narrowing the type now sees the type it passed in. Assisted-by: ClaudeCode:claude-opus-5-5
d-v-b
force-pushed
the
fix/zarr-metadata-guards-typeguard
branch
from
September 26, 2026 18:55
e48c105 to
93b192d
Compare
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 🤖
Breaking for type checkers.
TypeIs[T]promises True exactly for the values that areT, and type checkers narrowTaway when it returns False. Everyis_*guard inzarr_metadata.modelis stricter than its type:is_json(math.nan)is False for afloat, and the document guards are False for well-typed documents that break a structural rule. So this type-checks under pyright strict, and fails at run time:The guards are now
TypeGuards, which narrow only on True. zarr-python itself does not importzarr_metadatayet, so only outside consumers are affected.This is one of eight independent PRs from a review of the casts in
zarr_metadata.model, each based onmainand each passingjust checkalone, with a test that fails without its fix where there is behaviour to test:#4425, #4426, #4428 and #4430 have merged, as have #4420, #4421 and #4422, and each of the four left is rebased onto them, so its tests are type-checked as #4421 requires. Of those four, only #4423 and #4429 touch the same lines, the
TypeGuardimport, so whichever of them merges second needs a one-line rebase. All eight together, merged with #4421's type-checked tests, passjust check.🤖 Generated with Claude Code