anndata icon indicating copy to clipboard operation
anndata copied to clipboard

Add type-checking

Open szabgab opened this issue 2 months ago • 7 comments

  • Add .mypy.ini
  • Add mypy to pre-commit
  • Add mypy to GitHub Actioons
  • [X] Starts working on #2173
  • [X] Tests added
  • [X] Release note added (or unnecessary)

szabgab avatar Oct 25 '25 08:10 szabgab

I don't understand why we would add a GHA workflow instead of just adding mypy to the pre-commit config. The latter should suffice.

I also suggest that we put the mypy config into the pyproject.toml file.

Thanks @szabgab for getting this started!

Zethson avatar Oct 27 '25 09:10 Zethson

I've moved the mypy configuration to pyproject.toml and rebased the PR.

I still could not figure out why does mypy fail on the pre-commit.ci while passes on GHA. That's the reason I kept GHA.

szabgab avatar Oct 27 '25 13:10 szabgab

I still could not figure out why does mypy fail on the pre-commit.ci while passes on GHA. That's the reason I kept GHA.

Because pre-commit creates isolated environments. You’d need to duplicate all dependencies in .pre-commit-config.yaml to make it work, like here:

https://github.com/scverse/fast-array-utils/blob/6af5d9a339a78604ff62230e6462f3a7a94fec3f/.pre-commit-config.yaml#L24-L41

flying-sheep avatar Oct 28 '25 15:10 flying-sheep

It seems that rebasing to main broke mypy. Specifically this commit 470db9cc09bf5861234dbf0d9cb575cd3b68c12d The class name[] syntax seems something that mypy does not accept.

szabgab avatar Oct 29 '25 15:10 szabgab

Starting with version 1.12, mypy supports this syntax: https://mypy.readthedocs.io/en/latest/changelog.html#support-python-3-12-syntax-for-generics-pep-695

I see an internal error, so it’s for sure a mypy bug though!

flying-sheep avatar Oct 31 '25 12:10 flying-sheep

Seems like it’s either fixed on master or the “49 files” mypy checks are docs and stuff. No way it just succeeds.

flying-sheep avatar Oct 31 '25 12:10 flying-sheep

So maybe you could go ahead and merge this now. We might later move the mypy run to the pre-commit hook, though it seems it is also disabled on fast-array-utils

szabgab avatar Oct 31 '25 13:10 szabgab