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
This commit is contained in:
Alexander Hess 2026-11-30 13:15:19 +01:00
commit 570c9c9fcb
Signed by: alexander
GPG key ID: B46EDB4DFC26805D
2 changed files with 17 additions and 12 deletions

View file

@ -3,7 +3,7 @@
By default, `uv run nox` runs the sessions that assure code quality: By default, `uv run nox` runs the sessions that assure code quality:
- "format": Format source files with `autoflake`, `black`, `flynt`, `isort`, and `ruff` - "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` - "test": Run the test suite with `pytest`
- "doctest": Check if code snippets in the docstrings run - "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) @nox.session(name="lint", python=MAIN_PYTHON)
def lint_code(session: Session) -> None: 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. If no extra arguments are provided, all source files are linted.
Otherwise, they are interpreted as paths the linters work on recursively. 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) start(session)
# The linters do not need `velofy` installed
# because they work on the source files directly
install_pinned( install_pinned(
session, session,
# `mypy` needs the dependencies of `velofy` installed
# because otherwise it treats missing packages as `Any`
".",
"flake8", "flake8",
"flake8-annotations", "flake8-annotations",
"flake8-bandit", "flake8-bandit",
@ -204,8 +208,7 @@ def lint_code(session: Session) -> None:
"flake8-todos", "flake8-todos",
"flake8-unused-arguments", "flake8-unused-arguments",
"isort", "isort",
# TODO: See comment on `mypy` below "mypy",
# 'mypy',
"pep8-naming", "pep8-naming",
"pydoclint[flake8]", "pydoclint[flake8]",
"ruff", "ruff",
@ -225,12 +228,8 @@ def lint_code(session: Session) -> None:
session.run("ruff", "--version") session.run("ruff", "--version")
session.run("ruff", "check", *locations) session.run("ruff", "check", *locations)
# TODO: Include `mypy` once it passes session.run("mypy", "--version")
# - Only for the *.py files to be packaged session.run("mypy", PACKAGE_LOCATION)
# - 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
@nox.session(name="test", python=MAIN_PYTHON) @nox.session(name="test", python=MAIN_PYTHON)

View file

@ -364,6 +364,12 @@ untyped_calls_exclude = [
# Disallow functions without type annotations (or incomplete annotations) # Disallow functions without type annotations (or incomplete annotations)
disallow_untyped_defs = true 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]] [[tool.mypy.overrides]]