Skip to content

Conversation

@szabgab
Copy link
Contributor

@szabgab szabgab commented Oct 25, 2025

  • Add .mypy.ini
  • Add mypy to pre-commit
  • Add mypy to GitHub Actioons

@@ -0,0 +1,26 @@
name: Run mypy
Copy link
Contributor

@ilan-gold ilan-gold Oct 25, 2025

Choose a reason for hiding this comment

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

I think we have a pre-commit bot that already runs on PRs, so in theory should be running the added mypy to the .pre-commit-config.yaml

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right, Now I can see it is triggered in .github/workflows/check-pr.yml.
What is unclear to me why is it failing on the pre-commit.ci server. It seems that it does not take in account the .mypy.ini that excludes the duplicate files.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If I run pre-commit run -a locally, I get the same error as we can see on pre-commit.ci

mypy.....................................................................Failed
- hook id: mypy
- exit code: 2

src/anndata/_settings.pyi: error: Duplicate module named "anndata._settings" (also at "src/anndata/_settings.py")
Found 1 error in 1 file (errors prevented further checking)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've commented out mypy in the pre-commit hook to make ti pass on the pre-commit.ci server.
We still have it on GitHub Actions.
Either someone will figure out what's the problem on the pre-commit.ci server or this can be revisited later.

Copy link
Contributor

Choose a reason for hiding this comment

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

Re: what Lukas is saying in the review, it should probably be the reverse. We should figure out why things aren't working on the pre-commit ci instead of trying to use github actions.

@Zethson
Copy link
Member

Zethson commented Oct 27, 2025

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!

@szabgab
Copy link
Contributor Author

szabgab commented Oct 27, 2025

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.

@flying-sheep
Copy link
Member

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

@szabgab
Copy link
Contributor Author

szabgab commented Oct 29, 2025

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

@flying-sheep
Copy link
Member

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
Copy link
Member

flying-sheep commented Oct 31, 2025

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

@szabgab
Copy link
Contributor Author

szabgab commented Oct 31, 2025

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

- id: codespell
additional_dependencies:
- tomli
# See https://github.com/scverse/anndata/pull/2174
Copy link
Member

Choose a reason for hiding this comment

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

@@ -0,0 +1,27 @@
name: mypy
Copy link
Member

Choose a reason for hiding this comment

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

I still think that this whole workflow shouldn't exist and we can make it work with pre-commit. See below for the hammer - just exclude the unimportant conftest files.

python-version: ${{ env.max_python_version }}
- name: Install mypy
run: |
pip install 'mypy @ git+https://github.com/python/mypy.git'
Copy link
Member

@Zethson Zethson Nov 25, 2025

Choose a reason for hiding this comment

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

Even if we were to use this workflow, we shouldn't install from Github. We can just use a release.

@@ -1,5 +1,6 @@
ci:
autoupdate_commit_msg: "ci: pre-commit autoupdate"
skip: [mypy] # too big
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
skip: [mypy] # too big

Copy link
Member

Choose a reason for hiding this comment

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

@Zethson did you test that it works? pre-commit.ci often cries when the mypy environment contains a halfway useful subset of a package’s dependencies, so I basically have to add this skip to almost everything.

Copy link
Member

Choose a reason for hiding this comment

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

No I did not but I have never had to use it anywhere. But you're probably right then

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.

4 participants