Skip to content

Claude/py312 modernizations#4087

Merged
d-v-b merged 8 commits into
zarr-developers:mainfrom
d-v-b:claude/py312-modernizations
Jun 22, 2026
Merged

Claude/py312 modernizations#4087
d-v-b merged 8 commits into
zarr-developers:mainfrom
d-v-b:claude/py312-modernizations

Conversation

@d-v-b

@d-v-b d-v-b commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

I had claude do a review of our test suite. The tracking issue is on my fork of zarr-python.

Summary

Addresses M1–M5 of #181. Replaces Python <3.12 patterns with stdlib equivalents now that the minimum Python version is 3.12. Behavior is identical; no public API changes.

M1 — itertools.batched (codec_pipeline.py)

  • Deleted the hand-rolled batched() generator and the islice import it depended on.
  • Added batched to the existing from itertools import line.
  • No external callers import batched from this module (verified with grep across src/ and tests/).

M2 — collections.abc.Buffer (codecs/crc32c_.py)

  • Removed import typing_extensions.
  • Added from collections.abc import Buffer as ABCBuffer (stdlib since 3.12).
  • Replaced both cast("typing_extensions.Buffer", ...) calls with cast(ABCBuffer, ...).

M3 — Remove unused ParamSpec / P (core/sync.py)

  • Removed from typing_extensions import ParamSpec and the unused P = ParamSpec("P") assignment.
  • Verified with grep that nothing imports P from zarr.core.sync.

M4 — math.prod for integer products

  • common.py: Rewrote product() body as return math.prod(tup); removed the now-unused import functools and import operator. The name product is preserved because it is imported in src/zarr/codecs/numcodecs/_codecs.py, src/zarr/core/indexing.py, and tests/test_codecs/test_codecs.py.
  • indexing.py (~line 1190): Replaced reduce(operator.mul, cdata_shape, 1) with math.prod(cdata_shape); removed unused import operator and reduce from the functools import.
  • array.py (AsyncArray.size ~line 908): Replaced np.prod(self.metadata.shape).item() with math.prod(self.metadata.shape). self.metadata.shape is tuple[int, ...]. Added import math.
  • chunk_grids.py (~line 855, _guess_num_chunks_per_axis_shard): Replaced np.prod(chunk_shape) with math.prod(chunk_shape). chunk_shape is typed tuple[int, ...]. math already imported.
  • chunk_grids.py lines 689, 704, 711 SKIPPED: These operate on chunks = np.maximum(np.array(shape, dtype="=f8"), 1) — a numpy float64 array. Converting to math.prod would be incorrect (it expects an iterable of numbers and the semantics differ for floating-point arrays). Left unchanged.
  • numcodecs/_codecs.py ~21 SKIPPED: Line 21 is inside a docstring code example (np.arange(np.prod(array.shape),...)), not executable source. The actual production usage in that file already calls product() from zarr.core.common (line 264) and is unchanged.

M5 — pathlib in _local.py (~lines 366, 372)

  • os.path.exists(dest_root)dest_root.exists() (dest_root is a Path).
  • os.path.getsize(self.root / key)(self.root / key).stat().st_size.
  • import os retained — still used for os.makedirs, os.rename, os.link, os.unlink.

Test results

uv run pytest tests/test_codecs/test_codecs.py tests/test_store/ tests/test_indexing.py tests/test_common.py tests/test_codec_pipeline.py -q
1410 passed, 182 skipped, 5 xfailed in 51.00s

uv run pytest tests/test_codecs/test_crc32c.py tests/test_array.py tests/test_chunk_grids.py -q
1379 passed, 31 skipped in 9.59s

uv run mypy src/zarr/core/codec_pipeline.py src/zarr/codecs/crc32c_.py src/zarr/core/sync.py src/zarr/core/common.py src/zarr/core/indexing.py src/zarr/core/array.py src/zarr/core/chunk_grids.py src/zarr/codecs/numcodecs/_codecs.py src/zarr/storage/_local.py
Success: no issues found in 9 source files

Notes

  • A towncrier changelog entry should be added before un-drafting this PR.
  • All pre-commit hooks (ruff check, ruff format, mypy, codespell, numpydoc-validation, sp-repo-review) pass.

🤖 Generated with Claude Code

dependabot Bot and others added 8 commits May 31, 2026 19:28
…#176)

Bumps the actions group with 8 updates in the / directory:

| Package | From | To |
| --- | --- | --- |
| [prefix-dev/setup-pixi](https://github.com/prefix-dev/setup-pixi) | `0.9.5` | `0.9.6` |
| [codecov/codecov-action](https://github.com/codecov/codecov-action) | `6.0.0` | `6.0.1` |
| [github/issue-metrics](https://github.com/github/issue-metrics) | `4.2.2` | `4.2.7` |
| [j178/prek-action](https://github.com/j178/prek-action) | `2.0.3` | `2.0.4` |
| [actions/upload-artifact](https://github.com/actions/upload-artifact) | `7.0.0` | `7.0.1` |
| [actions/download-artifact](https://github.com/actions/download-artifact) | `7.0.0` | `8.0.1` |
| [pypa/gh-action-pypi-publish](https://github.com/pypa/gh-action-pypi-publish) | `1.13.0` | `1.14.0` |
| [zizmorcore/zizmor-action](https://github.com/zizmorcore/zizmor-action) | `0.5.3` | `0.5.6` |



Updates `prefix-dev/setup-pixi` from 0.9.5 to 0.9.6
- [Release notes](https://github.com/prefix-dev/setup-pixi/releases)
- [Commits](prefix-dev/setup-pixi@1b2de7f...5185adf)

Updates `codecov/codecov-action` from 6.0.0 to 6.0.1
- [Release notes](https://github.com/codecov/codecov-action/releases)
- [Changelog](https://github.com/codecov/codecov-action/blob/main/CHANGELOG.md)
- [Commits](codecov/codecov-action@57e3a13...e79a696)

Updates `github/issue-metrics` from 4.2.2 to 4.2.7
- [Release notes](https://github.com/github/issue-metrics/releases)
- [Commits](github-community-projects/issue-metrics@c9e9838...1e38d5e)

Updates `j178/prek-action` from 2.0.3 to 2.0.4
- [Release notes](https://github.com/j178/prek-action/releases)
- [Commits](j178/prek-action@6ad8027...bdca6f1)

Updates `actions/upload-artifact` from 7.0.0 to 7.0.1
- [Release notes](https://github.com/actions/upload-artifact/releases)
- [Commits](actions/upload-artifact@v7...043fb46)

Updates `actions/download-artifact` from 7.0.0 to 8.0.1
- [Release notes](https://github.com/actions/download-artifact/releases)
- [Commits](actions/download-artifact@v7...3e5f45b)

Updates `pypa/gh-action-pypi-publish` from 1.13.0 to 1.14.0
- [Release notes](https://github.com/pypa/gh-action-pypi-publish/releases)
- [Commits](pypa/gh-action-pypi-publish@v1.13.0...cef2210)

Updates `zizmorcore/zizmor-action` from 0.5.3 to 0.5.6
- [Release notes](https://github.com/zizmorcore/zizmor-action/releases)
- [Commits](zizmorcore/zizmor-action@b1d7e1f...5f14fd0)

---
updated-dependencies:
- dependency-name: prefix-dev/setup-pixi
  dependency-version: 0.9.6
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: actions
- dependency-name: codecov/codecov-action
  dependency-version: 6.0.1
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: actions
- dependency-name: github/issue-metrics
  dependency-version: 4.2.7
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: actions
- dependency-name: j178/prek-action
  dependency-version: 2.0.4
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: actions
- dependency-name: actions/upload-artifact
  dependency-version: 7.0.1
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: actions
- dependency-name: actions/download-artifact
  dependency-version: 8.0.1
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: actions
- dependency-name: pypa/gh-action-pypi-publish
  dependency-version: 1.14.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: actions
- dependency-name: zizmorcore/zizmor-action
  dependency-version: 0.5.6
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: actions
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
…, math.prod, pathlib

- Replace hand-rolled batched() in codec_pipeline.py with itertools.batched (stdlib 3.12+)
- Replace typing_extensions.Buffer with collections.abc.Buffer in crc32c_.py
- Remove unused ParamSpec / P from core/sync.py
- Replace functools.reduce(operator.mul) with math.prod in common.product(),
  indexing.py CoordinateIndexer.__init__, array.AsyncArray.size, and
  chunk_grids._guess_num_chunks_per_axis_shard
- Replace os.path.exists / os.path.getsize with pathlib equivalents in storage/_local.py

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@github-actions github-actions Bot added the needs release notes Automatically applied to PRs which haven't added release notes label Jun 22, 2026
@d-v-b d-v-b marked this pull request as ready for review June 22, 2026 09:12
@codecov

codecov Bot commented Jun 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.47%. Comparing base (4e79f1b) to head (c67b316).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4087   +/-   ##
=======================================
  Coverage   93.47%   93.47%           
=======================================
  Files          90       90           
  Lines       11967    11958    -9     
=======================================
- Hits        11186    11178    -8     
+ Misses        781      780    -1     
Files with missing lines Coverage Δ
src/zarr/codecs/crc32c_.py 97.22% <100.00%> (ø)
src/zarr/core/array.py 97.87% <100.00%> (+<0.01%) ⬆️
src/zarr/core/chunk_grids.py 96.94% <100.00%> (ø)
src/zarr/core/codec_pipeline.py 95.28% <100.00%> (+0.25%) ⬆️
src/zarr/core/common.py 88.69% <100.00%> (-0.14%) ⬇️
src/zarr/core/indexing.py 96.29% <100.00%> (ø)
src/zarr/core/sync.py 94.23% <ø> (-0.11%) ⬇️
src/zarr/storage/_local.py 95.04% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@d-v-b

d-v-b commented Jun 22, 2026

Copy link
Copy Markdown
Contributor Author

these are minor changes and reverting this PR would be very cheap. I am using an agent to review, and I will self-merge if nothing turns up

@d-v-b d-v-b merged commit 4427290 into zarr-developers:main Jun 22, 2026
30 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