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

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'
- 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

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
# 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