diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index cd63a7d..467074b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -55,3 +55,8 @@ repos: rev: v2.4.1 hooks: - id: codespell + - repo: https://github.com/pre-commit/mirrors-mypy + # Static type checker + rev: v1.14.1 + hooks: + - id: mypy diff --git a/README.md b/README.md index f35fefb..ac7f125 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ You can run the checks manually on all files: pre-commit run --all-files ``` -So far, **there is no types checking with mypy**. See [issue](https://github.com/roboflow-ai/template-python/issues/4). +We now use **mypy** for type checking. Type hints are enforced and checked automatically via pre-commit hooks. ### Tests 🧪 diff --git a/pyproject.toml b/pyproject.toml index d22c330..a698831 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -67,3 +67,9 @@ addopts = [ "--color=yes", "--doctest-modules", ] + +[tool.mypy] +python_version = "3.9" +warn_return_any = true +warn_unused_configs = true +disallow_untyped_defs = true diff --git a/test/test_hello.py b/test/test_hello.py index 39aab3d..55533af 100644 --- a/test/test_hello.py +++ b/test/test_hello.py @@ -3,7 +3,7 @@ from sandbox.hello import hello -def test_hello(): +def test_hello() -> None: """Test the hello function.""" res = hello() assert res == "World"