Skip to content

Commit 76089cb

Browse files
RFingAdamclaude
andcommitted
Fix all mypy type errors for CI
- validators.py: type enum_class parameter as type[enum.Enum] - dialog_handler.py: ignore attr-defined for Windows-only WINFUNCTYPE - vba.py, results.py: add type: ignore for safe indexed assignments - parameters.py, optimization.py, import_export.py: use Callable instead of builtin callable in type annotations - materials.py, optimization.py: add list type annotations - tools/__init__.py: cast lambda to ToolHandler Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent fda1fcb commit 76089cb

9 files changed

Lines changed: 17 additions & 15 deletions

File tree

src/mcp_cst_studio/dialog_handler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
user32 = ctypes.windll.user32 # type: ignore[attr-defined]
4141

4242
# Callback type for EnumWindows / EnumChildWindows
43-
WNDENUMPROC = ctypes.WINFUNCTYPE(wintypes.BOOL, wintypes.HWND, wintypes.LPARAM)
43+
WNDENUMPROC = ctypes.WINFUNCTYPE(wintypes.BOOL, wintypes.HWND, wintypes.LPARAM) # type: ignore[attr-defined]
4444

4545
# Constants
4646
WM_CLOSE = 0x0010

src/mcp_cst_studio/tools/__init__.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from __future__ import annotations
1414

1515
import logging
16-
from typing import TYPE_CHECKING, Awaitable, Callable
16+
from typing import TYPE_CHECKING, Awaitable, Callable, cast
1717

1818
from mcp.types import TextContent, Tool
1919

@@ -57,8 +57,9 @@ def add_module(
5757
for tool in tools:
5858
self._tools.append(tool)
5959
# Bind *client* at registration time so each call gets the right ref
60-
self._handlers[tool.name] = (
61-
lambda name, args, _h=handle_fn, _c=client: _h(name, args, _c)
60+
self._handlers[tool.name] = cast(
61+
ToolHandler,
62+
lambda name, args, _h=handle_fn, _c=client: _h(name, args, _c),
6263
)
6364

6465
# -- internal: wire into the MCP server --

src/mcp_cst_studio/tools/import_export.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from __future__ import annotations
88

99
import json
10-
from typing import TYPE_CHECKING
10+
from typing import TYPE_CHECKING, Callable
1111

1212
from mcp.types import TextContent, Tool
1313

@@ -335,7 +335,7 @@ def _build_export_farfield(args: dict) -> str:
335335
# Dispatch table
336336
# ---------------------------------------------------------------------------
337337

338-
_HANDLERS: dict[str, callable] = {
338+
_HANDLERS: dict[str, Callable[..., str]] = {
339339
"cst_import_cad": _build_import_cad,
340340
"cst_export_cad": _build_export_cad,
341341
"cst_import_touchstone": _build_import_touchstone,

src/mcp_cst_studio/tools/materials.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -832,7 +832,7 @@ def _handle_get_material_info(args: dict) -> list[TextContent]:
832832
if mat is None:
833833
# List available names to help the user
834834
db = _load_material_db()
835-
available = []
835+
available: list[str] = []
836836
for cat_list in db.values():
837837
available.extend(m["name"] for m in cat_list)
838838
return [TextContent(

src/mcp_cst_studio/tools/optimization.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import math
1818
import os
1919
import tempfile
20-
from typing import TYPE_CHECKING
20+
from typing import TYPE_CHECKING, Any, Callable
2121

2222
from mcp.types import TextContent, Tool
2323

@@ -363,7 +363,7 @@ def _find_resonances(
363363
364364
Returns list of {freq_ghz, s11_db, vswr} for each detected resonance.
365365
"""
366-
resonances = []
366+
resonances: list[dict] = []
367367
n = len(s11_db)
368368
if n < 3:
369369
return resonances
@@ -1445,7 +1445,7 @@ def _build_impedance_vba(port: int) -> str:
14451445
# Dispatch
14461446
# ---------------------------------------------------------------------------
14471447

1448-
_HANDLERS: dict[str, callable] = {
1448+
_HANDLERS: dict[str, Callable[..., Any]] = {
14491449
"cst_evaluate_antenna": _handle_evaluate,
14501450
"cst_analyze_impedance": _handle_analyze_impedance,
14511451
"cst_refine_antenna": _handle_refine,

src/mcp_cst_studio/tools/parameters.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from __future__ import annotations
88

99
import json
10-
from typing import TYPE_CHECKING
10+
from typing import TYPE_CHECKING, Callable
1111

1212
from mcp.types import TextContent, Tool
1313

@@ -934,7 +934,7 @@ def _build_parameter_interpolation(args: dict) -> str:
934934
# Dispatch table
935935
# ---------------------------------------------------------------------------
936936

937-
_HANDLERS: dict[str, callable] = {
937+
_HANDLERS: dict[str, Callable[..., str]] = {
938938
"cst_set_parameter": _build_set_parameter,
939939
"cst_get_parameter": _build_get_parameter,
940940
"cst_list_parameters": _build_list_parameters,

src/mcp_cst_studio/tools/results.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2263,7 +2263,7 @@ async def _handle_impl(name: str, arguments: dict, client: CSTClient) -> list[Te
22632263
# cst_list_results
22642264
# ------------------------------------------------------------------
22652265
if name == "cst_list_results":
2266-
tree_path = arguments.get("tree_path")
2266+
tree_path = arguments.get("tree_path") # type: ignore[assignment]
22672267

22682268
if client.connected:
22692269
vba = _build_list_results_vba(tree_path)

src/mcp_cst_studio/tools/vba.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ def _handle_list_vba_objects(args: dict) -> dict:
247247
# Return all categories with their objects
248248
result = {"status": "ok", "categories": {}}
249249
for cat, objects in ref.items():
250-
result["categories"][cat] = {
250+
result["categories"][cat] = { # type: ignore[index]
251251
name: data.get("description", "")
252252
for name, data in objects.items()
253253
}

src/mcp_cst_studio/validators.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from __future__ import annotations
44

5+
import enum
56
import re
67

78
# VBA commands that could be used for injection attacks
@@ -133,7 +134,7 @@ def validate_port_number(port: int) -> int:
133134
return port
134135

135136

136-
def validate_enum_value(value: str, enum_class: type, label: str = "value") -> str:
137+
def validate_enum_value(value: str, enum_class: type[enum.Enum], label: str = "value") -> str:
137138
"""Validate that a string matches an enum value."""
138139
valid = [e.value for e in enum_class]
139140
if value not in valid:

0 commit comments

Comments
 (0)