From 8d59cc726c04bdee1031bc0984543d4ff2a1ad10 Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Sun, 15 Feb 2026 14:51:38 -0500 Subject: [PATCH] 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 --- .pre-commit-config.yaml | 6 ++++++ pyproject.toml | 9 +++++++++ test-requirements.txt | 3 +++ tox.ini | 11 ++++++++++- 4 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 000000000..bdfcdcf02 --- /dev/null +++ b/.pre-commit-config.yaml @@ -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] diff --git a/pyproject.toml b/pyproject.toml index 5e862a959..a8f78b717 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 = [] \ No newline at end of file diff --git a/test-requirements.txt b/test-requirements.txt index de1c8817f..060cd6f0f 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -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 diff --git a/tox.ini b/tox.ini index a3687e16b..96a1a6a3f 100644 --- a/tox.ini +++ b/tox.ini @@ -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} \ No newline at end of file + 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} \ No newline at end of file