Skip to content

Commit

Permalink
Incorporate mypy into pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
bmerry committed Mar 20, 2024
1 parent d0272f4 commit 9e9b86e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
11 changes: 11 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 9 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
4 changes: 2 additions & 2 deletions python/katcp_codec/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 9e9b86e

Please sign in to comment.