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):

  1. Query PyPI for the latest stable mypy release.

  2. Compare against the current lower bound in pyproject.toml.

  3. If a newer version exists, update the >= specifier.

Post-update validation (overridden here):

  1. Recreate the types hatch environment to force fresh dependency resolution.

  2. Determine the highest supported Python version dynamically from pyproject.toml.

  3. Run mypy via hatch run types.py<version>:check.

  4. 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

MypyTool([project_root])

Manage the mypy static type checker version in pyproject.toml.

class mafw.devtools.toolchain.tools.mypy.MypyTool(project_root: Path | None = None)[source]

Bases: ProjectTool

Manage the mypy static type checker version in pyproject.toml.

Mypy is categorized as a project tool because its version is controlled through the types hatch environment extra-dependencies in pyproject.toml. After an update, the types environment 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. Only post_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:

  1. Forces recreation of the types hatch environment so that the newly specified dependency versions are resolved and installed.

  2. Determines the highest supported Python version dynamically from tool.mafw.supported-python in pyproject.toml.

  3. 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.toml is 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