Repository navigation
Conversation
Add tests/test_codec_contract.py, which runs every registered codec through the behavior the Codec base class promises: encode and decode return buffers, decode(out=...) returns the caller's out, and get_config round-trips through from_config. Known violations are strict xfails, so fixing one forces its entry to be removed. Add tests/typing, where assert_type checks (verified by mypy and pyright in strict mode) sit next to runtime assertions (verified by pytest), and a `typing` CI job that runs both checkers plus the repository's own mypy configuration. The type checkers are pinned in a new `typing` dependency group. Assisted-by: ClaudeCode:claude-opus-5-5
The Codec docstring says decode writes into `out`, and callers expect `out` back. Ten codecs (Zlib, BZ2, LZMA, Base64, Shuffle, ZFPY, PCodec and the three VLen codecs) rebound `out` to a flattened view and returned that, and numcodecs.compat.ndarray_copy did the same for any `out` that was not an ndarray, which every filter and checksum codec inherited. The decoded bytes were already in the caller's buffer; only the returned object changes. JenkinsLookup3.decode now accepts any contiguous writable buffer as `out` and checks its size, and Fletcher32.decode returns a uint8 ndarray instead of a Cython memoryview slice that no type annotation could name. The strict xfails in tests/test_codec_contract.py are removed. Assisted-by: ClaudeCode:claude-opus-5-5
… add __all__ Several annotations described something other than what the code does: - codec_registry holds classes: dict[str, type[Codec]], not dict[str, Codec]. - entries holds single entry points: dict[str, EntryPoint]. - ndarray_copy returned NDArrayLike, but hands back `src` unchanged (often bytes) when `dst` is None. It is now overloaded on `dst`. - NDArrayLike, DType and FlagsObj declared settable attributes, so no numpy.ndarray satisfied NDArrayLike under mypy or pyright. They now declare read-only properties. The isinstance cache moves to module level, because a protocol without annotations of its own would otherwise pick up the metaclass's annotation as a required member. The compat functions annotate their parameters with a new BufferLike alias (collections.abc.Buffer | NDArrayLike), is_ndarray_like returns TypeIs, and get_codec/register_codec are annotated. register_codec now refuses a class without a codec_id instead of registering it under None, and get_codec warns (DeprecationWarning) when an entry point loads a class that does not subclass Codec, so that `-> Codec` can become true. numcodecs/__init__.py defines __all__, so that type checkers treat the re-exported codec classes as public once numcodecs ships py.typed. mypy now checks against Python 3.12, the oldest supported version; doing so caught `typing.TypeIs`, which only exists from 3.13 and now comes from typing_extensions. Assisted-by: ClaudeCode:claude-opus-5-5
This was referenced Nov 21, 2026
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #908 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 27 27
Lines 922 939 +17
=========================================
+ Hits 922 939 +17
🚀 New features to boost your workflow:
|
# Conflicts: # tests/test_codec_contract.py
…ations # Conflicts: # docs/release.md # src/numcodecs/compat.py
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 🤖
Correct type annotations that described something other than what the code does, and define
__all__innumcodecsso type checkers treat its re-exported codec classes as public.register_codecnow raises for a class without acodec_id, and loading a non-Codecclass through thenumcodecs.codecsentry point group emits aDeprecationWarning.Summary
Annotations that were wrong:
codec_registrywas annotateddict[str, Codec]but holds classes; it is nowdict[str, type[Codec]].entrieswas annotateddict[str, EntryPoints]but holds singleEntryPoints.ndarray_copyclaimed to returnNDArrayLikebut returnssrcunchanged (oftenbytes) whendstisNone. It is now overloaded ondst.NDArrayLike,DTypeandFlagsObjdeclared settable attributes, so nonumpy.ndarraysatisfiedNDArrayLikeunder mypy or pyright. They now declare read-only properties.isinstancecache moves to module level. A protocol with no annotations of its own otherwise inherits the metaclass's__annotations__, andruntime_checkablethen demands the cache as a member.Other changes:
compatfunctions annotate their parameters with a newnumcodecs.ndarray_like.BufferLikealias (collections.abc.Buffer | NDArrayLike).is_ndarray_likereturnsTypeIs.get_codecandregister_codecare annotated.__all__innumcodecs/__init__.py: without it,numcodecs.Zliband friends count as private re-exports once the package shipspy.typed. As a side effect,from numcodecs import *now imports only the public names.typing.TypeIs, which only exists from 3.13 and now comes fromtyping_extensions.Tests
Full suite passes locally; there are new tests for
register_codecwithout an id and for the entry-point deprecation warning, plusassert_typetests forcompatandregistry.Stack and merge order
The agent split honest type annotations for numcodecs into a stack of 10 PRs, following an audit of the existing annotations and of the earlier attempts (#443, #698, #701, #702). Each PR is opened from the fork against
main, so until the PRs before it merge, its diff also contains their commits. The change specific to this PR starts at commit 52be3f5; later commits on its branch are follow-up fixes and merges of the PR below it. Merge in this order:typing/01-harness: test: check the Codec contract for every codec and add static type teststyping/02-out-contract: fix: return the caller's out from decode(buf, out=out) in every codectyping/03-fix-annotations: fix(typing): correct registry, compat and NDArrayLike annotations and add all ← this PRtyping/04-base-class: feat(abc): annotate the Codec base class and add structural codec protocolstyping/05-cython-stubs: feat(typing): ship .pyi stubs for the Cython extension modulestyping/06a-compressors: feat(typing): annotate the compressor codecs with per-codec config TypedDictstyping/06b-checksums: feat(typing): annotate the checksum codecs and make JenkinsLookup3 configs JSONtyping/06c-filters: feat(typing): annotate the filter codecstyping/06d-object-codecs: feat(typing): annotate the object and array-to-bytes codecstyping/07-py-typed: feat(typing): ship py.typed and check numcodecs with strict mypy🤖 Generated with Claude Code