Add mypy infrastructure for type annotation migration

This commit adds the tooling necessary to support gradual type
annotation of the codebase:
- Add mypy to test-requirements.txt
- Add mypy configuration to pyproject.toml with a list of
  type-checked modules (initially empty, to be populated as
  modules are migrated)
- Add tox mypy environment for running type checks
- Add mypy pre-commit hook

This follows the same pattern established in `ironic-prometheus-exporter`.

Change-Id: Ie9e4b5ebccff4ce29b4e014c62f09594d968d721
Signed-off-by: Karan Anand <anandkarancompsci@gmail.com>
This commit is contained in:
Karan Anand
2026-02-15 14:51:38 -05:00
parent fe9a35908c
commit 8d59cc726c
4 changed files with 28 additions and 1 deletions

6
.pre-commit-config.yaml Normal file
View File

@@ -0,0 +1,6 @@
repos:
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.14.1
hooks:
- id: mypy
args: [--config-file=pyproject.toml]

View File

@@ -1,3 +1,12 @@
[build-system]
requires = ["pbr>=6.0.0", "setuptools>=64.0.0"]
build-backend = "pbr.build"
[tool.mypy]
python_version = "3.10"
warn_return_any = true
warn_unused_configs = true
ignore_missing_imports = true
# Modules that have been fully type-annotated. Add modules here as they are
# migrated to enable strict type checking for them.
files = []

View File

@@ -7,3 +7,6 @@ tempest>=17.1.0 # Apache-2.0
stestr>=1.0.0 # Apache-2.0
ddt>=1.0.1 # MIT
python-openstackclient>=3.12.0 # Apache-2.0
# Type checking
mypy>=1.0.0 # MIT

11
tox.ini
View File

@@ -91,4 +91,13 @@ deps = codespell
# note(JayF): {posargs} lets us run `tox -ecodespell -- -w` to get codespell
# to correct spelling issues in our code it's aware of.
commands =
codespell {posargs}
codespell {posargs}
[testenv:mypy]
description =
Run type checks using mypy
deps =
-c{env:TOX_CONSTRAINTS_FILE:https://releases.openstack.org/constraints/upper/master}
-r{toxinidir}/requirements.txt
-r{toxinidir}/test-requirements.txt
commands = mypy {posargs}