Make mypy as strict as practical #13

Merged
alexander merged 32 commits from stricter-mypy into develop 2026-12-01 14:26:52 +01:00
2 changed files with 9 additions and 6 deletions
Showing only changes of commit d6b798a736 - Show all commits

Type-check scripts/

Alexander Hess 2026-12-01 13:57:42 +01:00
Signed by: alexander
GPG key ID: B46EDB4DFC26805D

View file

@ -89,6 +89,8 @@ PACKAGE_LOCATION = "src/"
DOCS_BUILD = ".cache/docs/"
DOCS_LOCATION = "docs/"
SCRIPTS_LOCATION = "scripts/"
TESTS_LOCATION = "tests/"
# Locations of all *.py files
@ -97,7 +99,7 @@ SRC_LOCATIONS = (
"migrations/env.py",
"migrations/versions/",
NOXFILE_LOCATION,
"scripts/",
SCRIPTS_LOCATION,
PACKAGE_LOCATION,
TESTS_LOCATION,
)
@ -186,7 +188,7 @@ def lint_code(session: nox.Session) -> None:
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 noxfile and the entire package regardless
`mypy` always checks the noxfile, the scripts, and the package regardless
because it needs the whole program to follow types across modules.
"""
start(session)
@ -250,7 +252,7 @@ def lint_code(session: nox.Session) -> None:
session.run("ruff", "check", *locations)
session.run("mypy", "--version")
session.run("mypy", NOXFILE_LOCATION, PACKAGE_LOCATION)
session.run("mypy", NOXFILE_LOCATION, SCRIPTS_LOCATION, PACKAGE_LOCATION)
@nox.session(name="test", python=MAIN_PYTHON)

View file

@ -14,6 +14,7 @@ import json
import pathlib
import textwrap
import tomllib
import typing as t
PKG_CONSIDERED_OLD = 2 # years after release when a package is considered "old"
@ -23,7 +24,7 @@ PROJECT_ROOT = pathlib.Path(__file__).resolve().parent.parent
REPORT_FILE = PROJECT_ROOT / ".cache/dependencies_checked.txt"
def get_direct_dependencies(lock_file: dict) -> dict[str, str]:
def get_direct_dependencies(lock_file: dict[str, t.Any]) -> dict[str, str]:
"""Map the direct dependencies to "main" or their extra or group.
`lock_file` is a mapping as returned from `load_lock_file()`.
@ -41,7 +42,7 @@ def get_direct_dependencies(lock_file: dict) -> dict[str, str]:
return labels
def get_pinned_packages(lock_file: dict) -> dict[str, str]:
def get_pinned_packages(lock_file: dict[str, t.Any]) -> dict[str, str]:
"""Map all packages from PyPI to their versions.
`lock_file` is a mapping as returned from `load_lock_file()`.
@ -84,7 +85,7 @@ def get_years_since_release(
return round(years_since_release, 1), latest_version
def load_lock_file() -> dict:
def load_lock_file() -> dict[str, t.Any]:
"""Load the uv.lock file."""
return tomllib.loads((PROJECT_ROOT / "uv.lock").read_text())