Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .github/workflows/mypy.yml
Original file line number Diff line number Diff line change
@@ -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.


on:
push:
pull_request:

jobs:
mypy:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v5
- name: Extract max Python version from classifiers
run: |
classifiers=$(yq .project.classifiers pyproject.toml -oy | grep --only-matching --perl-regexp '(?<=Python :: )(\d\.\d+)')
max_version=$(echo "$classifiers" | sort -V | tail -1)
echo "max_python_version=$max_version" >> $GITHUB_ENV
- uses: actions/setup-python@v6
with:
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.

- name: Run mypy
run: |
mypy --show-traceback src
23 changes: 23 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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


repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
Expand Down Expand Up @@ -39,3 +40,25 @@ repos:
- 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.

# Running `pre-commit run -a` gives the following error:
# tests/conftest.py: error: Duplicate module named "conftest" (also at "./tests/lazy/conftest.py")
# tests/conftest.py: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#mapping-file-paths-to-modules for more info
# This seems to be the same failure we get on the prec-commit.ci
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.18.2
hooks:
- id: mypy
args: [--config-file=pyproject.toml, --tb, .]
pass_filenames: false
additional_dependencies:
- array-api-compat
- h5py
- legacy-api-wrap
- natsort
- numpy
- packaging
- pandas
- scipy
- types-docutils
- zarr
2 changes: 1 addition & 1 deletion ci/scripts/min-deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def extract_min_deps(
dependencies = deque(dependencies) # We'll be mutating this
project_name = pyproject["project"]["name"]

deps = {}
deps: dict[str, Requirement] = {}
while len(dependencies) > 0:
req = dependencies.pop()

Expand Down
43 changes: 43 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -265,3 +265,46 @@ fragment.perf.name = "Performance"
fragment.chore.name = "Miscellaneous changes"
fragment.revert.name = "Revert"
fragment.breaking.name = "Breaking changes" # add `!` to commit type (e.g. “feature!:”)

[tool.mypy]
exclude = [
'^src/testing/anndata/__init__\.py$',
'^src/testing/anndata/_doctest\.py$',
]
explicit_package_bases = true
ignore_missing_imports = true
mypy_path = [ '$MYPY_CONFIG_FILE_DIR/src' ]

[[tool.mypy.overrides]]
module = [ "anndata/*" ]

disable_error_code = [
"import-untyped",
"no-redef",
"attr-defined",
"union-attr",
"index",
"assignment",
"arg-type",
"return-value",
"type-arg",
"type-var",
"return",
"call-arg",
"misc",
"override",
"valid-type",
"has-type",
"name-defined",
"var-annotated",
"call-overload",
"operator",
"list-item",
]

[[tool.mypy.overrides]]
module = [ "testing/*" ]

disable_error_code = [
"attr-defined",
]
Loading