numcodecs icon indicating copy to clipboard operation
numcodecs copied to clipboard

(chore) Type hints for abc codec `codec_id` attribute

Open d-v-b opened this issue 11 months ago • 3 comments

I'm not sure how to type the buffer parameters. As long as we have a pickle codec, I don't think it's possible to restrict the return type of decode to anything narrower than object.

  • [ ] Unit tests and/or doctests in docstrings
  • [ ] Tests pass locally
  • [ ] Docstrings and API docs for any new/modified user-facing classes and functions
  • [ ] Changes documented in docs/release.rst
  • [ ] Docs build locally
  • [ ] GitHub Actions CI passes
  • [ ] Test coverage to 100% (Codecov passes)

d-v-b avatar Feb 09 '25 10:02 d-v-b

i'm just annotating the type of the codec_id attribute -- it's a ClassVar[str], (no default value) instead of str | None = None

d-v-b avatar Feb 12 '25 10:02 d-v-b

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 99.96%. Comparing base (a2bdbe5) to head (c22b97f).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #702   +/-   ##
=======================================
  Coverage   99.96%   99.96%           
=======================================
  Files          63       63           
  Lines        2754     2754           
=======================================
  Hits         2753     2753           
  Misses          1        1           
Files with missing lines Coverage Δ
numcodecs/abc.py 100.00% <100.00%> (ø)
numcodecs/tests/test_registry.py 100.00% <ø> (ø)

codecov[bot] avatar Feb 12 '25 10:02 codecov[bot]

I think my suggested change (that I applied) revealed (sort of) a real issue - Checksum32 is a base class, not a codec that can be used by itself. I've made this better by making it an abstract base class in https://github.com/zarr-developers/numcodecs/pull/711 - if/when that's merged, we can update the check here in the test to not isinstance(codec, abc.ABC).

dstansby avatar Mar 01 '25 11:03 dstansby