Skip to content

fix(api): drop unreachable scalar branch in save_array - #4554

Open
d-v-b wants to merge 3 commits into
zarr-developers:mainfrom
d-v-b:fix/save-array-dead-scalar-branch
Open

d-v-b wants to merge 3 commits into
zarr-developers:mainfrom
d-v-b:fix/save-array-dead-scalar-branch

Conversation

@d-v-b

@d-v-b d-v-b commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

This PR avoids an unnecessary branch in save_array, and thereby makes that routine pass type checking on newer versions of numpy, thereby avoiding this lint failure which occurred during CI for an automatic dependency bump PR.

Here are claude's impressions:

🤖 Ai text 🤖

save_array rejects anything that is not NDArrayLike before it reaches np.isscalar(arr). numpy scalars lack __len__ and __setitem__, so they never pass the protocol check, and the np.array(arr) fallback was dead.

numpy 2.5.4 changed the np.isscalar stub from TypeGuard to TypeIs, which lets mypy intersect the narrowed NDArrayLike with the scalar union and report the branch as unreachable. Delete it and pin the error path.

Assisted-by: ClaudeCode:claude-fable-5-1

Author attestation

  • I am a human, these are my changes, and I have reviewed and understood every change and can explain why each is correct.

TODO

  • Add unit tests and/or doctests in docstrings
  • Add docstrings and API docs for any new/modified user-facing classes and functions
  • New/modified features documented in docs/user-guide/*.md
  • Changes documented as a new file in changes/
  • GitHub Actions have all passed
  • Test coverage is 100% (Codecov passes)

`save_array` rejects anything that is not `NDArrayLike` before it reaches
`np.isscalar(arr)`. numpy scalars lack `__len__` and `__setitem__`, so they
never pass the protocol check, and the `np.array(arr)` fallback was dead.

numpy 2.5.4 changed the `np.isscalar` stub from `TypeGuard` to `TypeIs`,
which lets mypy intersect the narrowed `NDArrayLike` with the scalar union
and report the branch as unreachable. Delete it and pin the error path.

Assisted-by: ClaudeCode:claude-fable-5-1
@github-actions github-actions Bot added the needs release notes Automatically applied to PRs which haven't added release notes label Oct 22, 2026
@d-v-b
d-v-b marked this pull request as ready for review October 22, 2026 20:04
@codecov

codecov Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.72%. Comparing base (957a5f6) to head (5607342).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4554      +/-   ##
==========================================
+ Coverage   94.71%   94.72%   +0.01%     
==========================================
  Files          94       94              
  Lines       13663    13661       -2     
==========================================
  Hits        12941    12941              
+ Misses        722      720       -2     
Files with missing lines Coverage Δ
src/zarr/api/asynchronous.py 97.15% <ø> (+0.68%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Assisted-by: ClaudeCode:claude-opus-5-5
@github-actions github-actions Bot removed the needs release notes Automatically applied to PRs which haven't added release notes label Oct 22, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant