diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1043432..1ac5b5d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -17,6 +17,17 @@ repos: rev: v0.3.3 hooks: - id: ruff + - repo: https://github.com/pre-commit/mirrors-mypy + rev: v1.9.0 + hooks: + - id: mypy + # Passing filenames to mypy can do odd things. + # pyproject.toml determines the set of files that will actually be checked. + pass_filenames: false + # The pre-commit hook passes some options, but we set options in pyproject.toml. + args: [] + additional_dependencies: + - pytest==8.1.1 - repo: https://github.com/jazzband/pip-tools rev: 7.4.1 hooks: diff --git a/pyproject.toml b/pyproject.toml index a325345..59d92f8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -52,5 +52,14 @@ debug = false profile = "black" known_first_party = ["katcp_codec"] +[tool.mypy] +python_version = "3.8" +files = "python" + +[[tool.mypy.overrides]] +# The Rust module doesn't have type hints +module = "katcp_codec._lib" +ignore_missing_imports = true + [tool.pytest.ini_options] testpaths = "python/tests" diff --git a/python/katcp_codec/__init__.py b/python/katcp_codec/__init__.py index 72752c8..05dd89e 100644 --- a/python/katcp_codec/__init__.py +++ b/python/katcp_codec/__init__.py @@ -18,7 +18,7 @@ from dataclasses import dataclass from typing import List, Optional, Union -from . import _lib +from . import _lib # type: ignore # Note: the values must correspond to those in message.rs @@ -51,7 +51,7 @@ def __bytes__(self) -> bytes: def _message_from_rust( message: Union[_lib.Message, ValueError] ) -> Union[Message, ValueError]: - if isinstance(message, Exception): + if isinstance(message, ValueError): return message else: return Message(