launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #27718
[Merge] ~cjwatson/lpcraft:mypy into lpcraft:main
Colin Watson has proposed merging ~cjwatson/lpcraft:mypy into lpcraft:main.
Commit message:
Add type checks using mypy
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~cjwatson/lpcraft/+git/lpcraft/+merge/411761
--
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/lpcraft:mypy into lpcraft:main.
diff --git a/lpcraft/_version.py b/lpcraft/_version.py
index 144bb8d..2d1f181 100644
--- a/lpcraft/_version.py
+++ b/lpcraft/_version.py
@@ -11,7 +11,7 @@ from configparser import ConfigParser
from pathlib import Path
-def _get_version():
+def _get_version() -> str:
try:
return importlib.metadata.version("lpcraft")
except importlib.metadata.PackageNotFoundError:
diff --git a/lpcraft/errors.py b/lpcraft/errors.py
index 264c7e2..978fe08 100644
--- a/lpcraft/errors.py
+++ b/lpcraft/errors.py
@@ -11,5 +11,5 @@ __all__ = [
class CommandError(Exception):
"""Base exception for all error commands."""
- def __init__(self, message):
+ def __init__(self, message: str):
super().__init__(message)
diff --git a/lpcraft/main.py b/lpcraft/main.py
index 0f547f8..8babce8 100644
--- a/lpcraft/main.py
+++ b/lpcraft/main.py
@@ -11,7 +11,7 @@ from craft_cli import EmitterMode, emit
from lpcraft._version import version_description as lpcraft_version
-def _configure_logger(name):
+def _configure_logger(name: str) -> None:
"""Configure a logger for use with craft-cli.
Setting up a library's logger in DEBUG level causes its content to be
@@ -24,7 +24,7 @@ def _configure_logger(name):
_configure_logger("craft_providers")
-def main():
+def main() -> int:
"""lpcraft runs Launchpad CI jobs."""
parser = ArgumentParser(description="Run Launchpad CI jobs.")
parser.add_argument(
diff --git a/pyproject.toml b/pyproject.toml
index a8f43fe..4af21f6 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -1,2 +1,28 @@
[tool.black]
line-length = 79
+
+[tool.mypy]
+python_version = 3.8
+check_untyped_defs = true
+disallow_any_generics = true
+disallow_incomplete_defs = true
+disallow_untyped_calls = true
+disallow_untyped_decorators = true
+disallow_untyped_defs = true
+no_implicit_optional = true
+warn_redundant_casts = true
+warn_return_any = true
+warn_unused_configs = true
+warn_unused_ignores = true
+
+[[tool.mypy.overrides]]
+module = "*.tests.*"
+disallow_untyped_calls = false
+disallow_untyped_defs = false
+
+[[tool.mypy.overrides]]
+module = [
+ "fixtures",
+ "testtools",
+]
+ignore_missing_imports = true
diff --git a/tox.ini b/tox.ini
index 7d224d2..7916b92 100644
--- a/tox.ini
+++ b/tox.ini
@@ -27,3 +27,12 @@ deps =
skip_install = true
commands =
pip-compile
+
+[testenv:mypy]
+basepython =
+ python3.8
+deps =
+ -r requirements.txt
+ mypy
+commands =
+ mypy {posargs:lpcraft}
Follow ups