From be4a7533e3b7dd9f6114b109e28e1ee35d55f3ae Mon Sep 17 00:00:00 2001 From: heznpc Date: Thu, 23 Apr 2026 03:43:53 +0900 Subject: [PATCH] chore: add mypy strict type checking MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - pyproject.toml: add mypy to dev deps, [tool.mypy] with strict = true, override to relax tests - ci.yml: add 'Type check' step running mypy src/ on all 3 Python versions - server.py: tighten dict annotations to dict[str, object] to pass strict mode Locally: mypy src/ → 'Success: no issues found in 5 source files'. pytest + ruff still green. --- .github/workflows/ci.yml | 3 +++ pyproject.toml | 14 ++++++++++++++ src/my_mcp_server/server.py | 4 ++-- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4705422..f8cb7b5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -69,5 +69,8 @@ jobs: - name: Format check run: ruff format --check . + - name: Type check + run: mypy src/ + - name: Test run: pytest -v diff --git a/pyproject.toml b/pyproject.toml index b55a333..45d1aab 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -33,6 +33,7 @@ dev = [ "pytest", "pytest-asyncio", "ruff", + "mypy", ] [tool.ruff] @@ -42,6 +43,19 @@ line-length = 100 [tool.ruff.lint] select = ["E", "F", "I", "N", "W", "UP"] +[tool.mypy] +python_version = "3.11" +strict = true +warn_unused_ignores = true +warn_redundant_casts = true +warn_unreachable = true +show_error_codes = true +exclude = ["build/", "dist/"] + +[[tool.mypy.overrides]] +module = "tests.*" +disallow_untyped_defs = false + [tool.pytest.ini_options] asyncio_mode = "auto" testpaths = ["tests"] diff --git a/src/my_mcp_server/server.py b/src/my_mcp_server/server.py index c593abf..7828376 100644 --- a/src/my_mcp_server/server.py +++ b/src/my_mcp_server/server.py @@ -33,13 +33,13 @@ # --------------------------------------------------------------------------- -def ok(data: str | dict) -> dict: +def ok(data: str | dict[str, object]) -> dict[str, object]: """Return a successful tool response.""" text = data if isinstance(data, str) else str(data) return {"content": [{"type": "text", "text": text}]} -def err(message: str) -> dict: +def err(message: str) -> dict[str, object]: """Return an error tool response.""" return {"content": [{"type": "text", "text": message}], "isError": True}