mafw.devtools.toolchain.tools.mypy
Concrete ProjectTool implementation for mypy.
Mypy is a project tool whose version lower bound is declared in
tool.hatch.envs.types.extra-dependencies. This module manages the >=
specifier for mypy and validates updates by running type checking via the
types hatch environment.
Update logic (inherited from ProjectTool):
Query PyPI for the latest stable mypy release.
Compare against the current lower bound in pyproject.toml.
If a newer version exists, update the
>=specifier.
Post-update validation (overridden here):
Recreate the
typeshatch environment to force fresh dependency resolution.Determine the highest supported Python version dynamically from pyproject.toml.
Run mypy via
hatch run types.py<version>:check.If the type check fails, revert pyproject.toml to its previous content.
The revert pattern uses _revert() which restores the raw pyproject.toml
content saved before the update.
Classes
|
Manage the mypy static type checker version in pyproject.toml. |
- class mafw.devtools.toolchain.tools.mypy.MypyTool(project_root: Path | None = None)[source]
Bases:
ProjectToolManage the mypy static type checker version in pyproject.toml.
Mypy is categorized as a project tool because its version is controlled through the
typeshatch environment extra-dependencies inpyproject.toml. After an update, thetypesenvironment is recreated and mypy type checking is executed at the highest supported Python version to validate compatibility. If the check fails, pyproject.toml is reverted to its pre-update state.All standard behaviour (version detection, update, verify, bootstrap) is provided by
ProjectTool. Onlypost_update()is overridden to run mypy type checking.- Parameters:
project_root (Path | None) – Path to the project root directory containing
pyproject.toml. Defaults to the current working directory.
- post_update() None[source]
Recreate the types environment and run mypy type checking.
Performs the following steps after a successful version update:
Forces recreation of the
typeshatch environment so that the newly specified dependency versions are resolved and installed.Determines the highest supported Python version dynamically from
tool.mafw.supported-pythonin pyproject.toml.Runs mypy via
hatch run types.py<version>:check.
If environment recreation fails due to a dependency conflict, the conflicting package name is extracted and reported. If the type check fails,
pyproject.tomlis reverted to its pre-update state.- Raises:
DevtoolsError – If environment recreation fails or the mypy check exits with a non-zero exit code.
- property env_name: str
Hatch environment where mypy is validated.
- Returns:
"types"- Return type:
str
- property package_name: str
PyPI package name.
- Returns:
"mypy"- Return type:
str
- property section_path: str
TOML section path where mypy is declared.
- Returns:
"tool.hatch.envs.types.extra-dependencies"- Return type:
str