From ebc2e88415ef7565a45564189fbed86036c17ba7 Mon Sep 17 00:00:00 2001 From: Ian Campbell Date: Fri, 23 Aug 2024 12:05:25 -0400 Subject: [PATCH] Add MyPy type checking and a GitHub Action to automatically check this. --- .github/workflows/mypy.yml | 22 ++++++++++++++++++++++ mypy.ini | 26 ++++++++++++++++++++++++++ requirements-dev.txt | 4 ++++ 3 files changed, 52 insertions(+) create mode 100644 .github/workflows/mypy.yml create mode 100644 mypy.ini diff --git a/.github/workflows/mypy.yml b/.github/workflows/mypy.yml new file mode 100644 index 00000000..485085f5 --- /dev/null +++ b/.github/workflows/mypy.yml @@ -0,0 +1,22 @@ +--- +name: Run mypy +on: + pull_request: + push: + branches: ["main", "v[0-9]*"] + tags: ["v[0-9]*"] + workflow_dispatch: +jobs: + mypy: + runs-on: ubuntu-22.04 + steps: + - name: apt update + run: sudo apt update + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + - name: Install Python dependencies + run: | + python -m pip install --upgrade pip wheel + pip install -r requirements-dev.txt + - name: MyPy + run: mypy . diff --git a/mypy.ini b/mypy.ini new file mode 100644 index 00000000..75784074 --- /dev/null +++ b/mypy.ini @@ -0,0 +1,26 @@ +[mypy] +plugins = mypy_django_plugin.main +# TODO: Check all code in the future +check_untyped_defs = False +disallow_any_generics = False +disallow_incomplete_defs = False +disallow_subclassing_any = False +disallow_untyped_calls = False +disallow_untyped_defs = False +ignore_missing_imports = True +no_implicit_optional = True +no_implicit_reexport = True +strict = True +warn_return_any = False +# TODO: Remove this exception in the future +disable_error_code = var-annotated + +[mypy.plugins.django-stubs] +django_settings_module = "tests.test_settings.settings_5_0" + +# TODO: Type check tests in the future +[mypy-tests.*] +ignore_errors = True + +[mypy-docs.*] +ignore_errors = True diff --git a/requirements-dev.txt b/requirements-dev.txt index 753eb1c2..ed8928a2 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,5 +1,9 @@ # Requirements for developing (not just using) the package +django-stubs hatch +mypy pre-commit +requests tox<4 +types-requests