Skip to content

chore: update pre-commit hook mypy#835

Open
DimitriPapadopoulos wants to merge 1 commit intozarr-developers:mainfrom
DimitriPapadopoulos:mypy
Open

chore: update pre-commit hook mypy#835
DimitriPapadopoulos wants to merge 1 commit intozarr-developers:mainfrom
DimitriPapadopoulos:mypy

Conversation

@DimitriPapadopoulos
Copy link
Copy Markdown
Contributor

@DimitriPapadopoulos DimitriPapadopoulos commented Apr 12, 2026

updates:

  • github.com/pre-commit/mirrors-mypy: v1.16.0 → v1.20.0 v1.18.2

TODO:

  • 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)

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 12, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.89%. Comparing base (e46dfcf) to head (53c3e5e).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff             @@
##              main     #835      +/-   ##
===========================================
- Coverage   100.00%   98.89%   -1.11%     
===========================================
  Files           27       27              
  Lines          901      901              
===========================================
- Hits           901      891      -10     
- Misses           0       10      +10     

see 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread tests/test_zarr3.py Outdated
match="The numcodecs.zarr3 module is deprecated and will be removed in a future release of numcodecs. ",
):
assert getattr(zarr3, codec_name) == getattr(zarr.codecs.numcodecs, codec_name)
assert getattr(zarr3, codec_name) == getattr(zarr.codecs.numcodecs, codec_name) # type: ignore[attr-defined]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need a new type: ignore here? Is this improved type safety (if so, how?) or is this a regression in mypy

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a regression, but I often have a hard time understanding Python typing. The error can be seen in https://results.pre-commit.ci/run/github/68207196/1775503887.A9wQYmi0SzyJZg-CuQfz6A:

tests/test_zarr3.py:48: error: Module has no attribute "codecs"

I understand MyPy believes that the zarr>=3.1.3 module does not have a codecs submodule. I don't see why:
https://github.com/zarr-developers/zarr-python/tree/de947648e6ab6e7079ddb4f33b6b56070c3e6657/src/zarr/codecs

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the only effect of this version bump is a new mypy bug to mitigate, then maybe we wait for 1.20.1 😅

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me find which exact version introduces this issue.

Copy link
Copy Markdown
Contributor Author

@DimitriPapadopoulos DimitriPapadopoulos Apr 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strange, I cannot reproduce this issue outside pre-commit, instead I get other similar and nonsensical error messages with MyPy ≥ 1.19.0:

$ uvx mypy@v1.18.2 tests
Success: no issues found in 39 source files
$ 
$ uvx mypy@v1.19.0 tests
tests/test_checksum32.py:19: error: Module has no attribute "util"  [attr-defined]
tests/test_checksum32.py:20: error: Module has no attribute "util"  [attr-defined]
Found 2 errors in 1 file (checked 39 source files)
$ 
$ uvx mypy@v1.20.0 tests
tests/test_checksum32.py:19: error: Module has no attribute "util"  [attr-defined]
tests/test_checksum32.py:20: error: Module has no attribute "util"  [attr-defined]
Found 2 errors in 1 file (checked 39 source files)
$ 

The module is importlib:

has_google_crc32c = importlib.util.find_spec("google_crc32c") is not None
has_legacy_crc32c = importlib.util.find_spec("crc32c") is not None

and of course importlib does have the util submodule.

I fail to understand why MyPy emits different errors within pre-commit and outside pre-commit.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Meanwhile, let's bump to 1.18.2.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's easy to fix for MyPy ≥ 1.19.0:

-    import zarr.
+    import zarr.codecs

Not sure it makes sense, but it doesn't hurt.

I still fail to understand why MyPy emits different errors within pre-commit and outside pre-commit.

updates:
- github.com/pre-commit/mirrors-mypy: v1.16.0 → v1.20.0

Also enforce consistent indentation in the YAML config file.
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.

2 participants