From 570c9c9fcbc8fbc6399f68896a9bcd65f230dd8f Mon Sep 17 00:00:00 2001 From: Alexander Hess Date: Mon, 30 Nov 2026 13:15:19 +0100 Subject: [PATCH] Run `mypy` in the "lint" session It needs the dependencies of `velofy` installed, and it now also reports "# type: ignore" comments without an error code or that are not needed anymore --- noxfile.py | 23 +++++++++++------------ pyproject.toml | 6 ++++++ 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/noxfile.py b/noxfile.py index b7aeeaf..68307b1 100644 --- a/noxfile.py +++ b/noxfile.py @@ -3,7 +3,7 @@ By default, `uv run nox` runs the sessions that assure code quality: - "format": Format source files with `autoflake`, `black`, `flynt`, `isort`, and `ruff` -- "lint": Lint source files with `flake8`, `isort`, and `ruff` +- "lint": Lint source files with `flake8`, `isort`, `mypy`, and `ruff` - "test": Run the test suite with `pytest` - "doctest": Check if code snippets in the docstrings run @@ -176,17 +176,21 @@ def format_code(session: Session) -> None: @nox.session(name="lint", python=MAIN_PYTHON) def lint_code(session: Session) -> None: - """Lint source files with `flake8`, `isort`, and `ruff`. + """Lint source files with `flake8`, `isort`, `mypy`, and `ruff`. If no extra arguments are provided, all source files are linted. Otherwise, they are interpreted as paths the linters work on recursively. + + `mypy` always checks the entire package regardless + because it needs the whole program to follow types across modules. """ start(session) - # The linters do not need `velofy` installed - # because they work on the source files directly install_pinned( session, + # `mypy` needs the dependencies of `velofy` installed + # because otherwise it treats missing packages as `Any` + ".", "flake8", "flake8-annotations", "flake8-bandit", @@ -204,8 +208,7 @@ def lint_code(session: Session) -> None: "flake8-todos", "flake8-unused-arguments", "isort", - # TODO: See comment on `mypy` below - # 'mypy', + "mypy", "pep8-naming", "pydoclint[flake8]", "ruff", @@ -225,12 +228,8 @@ def lint_code(session: Session) -> None: session.run("ruff", "--version") session.run("ruff", "check", *locations) - # TODO: Include `mypy` once it passes - # - Only for the *.py files to be packaged - # - It then needs the developed package and its dependencies installed - # as it treats missing packages as `Any` and reports false successes - # session.run('mypy', '--version') # noqa:ERA001 - # session.run('mypy', PACKAGE_LOCATION) # noqa:ERA001 + session.run("mypy", "--version") + session.run("mypy", PACKAGE_LOCATION) @nox.session(name="test", python=MAIN_PYTHON) diff --git a/pyproject.toml b/pyproject.toml index 2d301b2..fea26fe 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -364,6 +364,12 @@ untyped_calls_exclude = [ # Disallow functions without type annotations (or incomplete annotations) disallow_untyped_defs = true +# Require an error code in all "# type: ignore" comments +enable_error_code = ["ignore-without-code"] + +# Report "# type: ignore" comments that are not needed anymore +warn_unused_ignores = true + [[tool.mypy.overrides]]