Skip to content

Commit 76f3b1f

Browse files
haasonsaasclaude
andcommitted
Add mypy configuration and fix critical type issues
- Install types-PyYAML for proper YAML type checking - Fix Optional types in server.py to handle None cases properly - Add mypy configuration in pyproject.toml with strict settings - Add dev dependencies with mypy and type stubs - Fix CLI Path type conversion for recordings_dir Remaining minor type annotations can be addressed in future PRs. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 7c3b575 commit 76f3b1f

File tree

3 files changed

+33
-5
lines changed

3 files changed

+33
-5
lines changed

pyproject.toml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,32 @@ test = [
3838
"pytest>=7.0",
3939
"pytest-asyncio>=0.21",
4040
]
41+
dev = [
42+
"mypy>=1.0",
43+
"types-PyYAML",
44+
"pytest>=7.0",
45+
"pytest-asyncio>=0.21",
46+
]
4147

4248
[tool.pytest.ini_options]
4349
addopts = "-q"
4450
asyncio_mode = "auto"
51+
52+
[tool.mypy]
53+
python_version = "3.9"
54+
warn_return_any = true
55+
warn_unused_configs = true
56+
disallow_untyped_defs = true
57+
disallow_incomplete_defs = true
58+
check_untyped_defs = true
59+
disallow_untyped_decorators = true
60+
no_implicit_optional = true
61+
warn_redundant_casts = true
62+
warn_unused_ignores = true
63+
warn_no_return = true
64+
warn_unreachable = true
65+
strict_equality = true
66+
67+
[[tool.mypy.overrides]]
68+
module = "tests.*"
69+
disallow_untyped_defs = false

src/mocktopus/cli.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
import sys
44
import logging
5-
from typing import List, Dict, Any
5+
from pathlib import Path
6+
from typing import List, Dict, Any, Optional
67
import click
78

89
from .core import Scenario, load_yaml
@@ -58,7 +59,7 @@ def serve_cmd(scenario: str, port: int, host: str, mode: str, recordings_dir: st
5859
server = MockServer(
5960
scenario=scenario_obj,
6061
mode=server_mode,
61-
recordings_dir=recordings_dir,
62+
recordings_dir=Path(recordings_dir) if recordings_dir else None,
6263
real_openai_key=openai_key,
6364
real_anthropic_key=anthropic_key,
6465
host=host,

src/mocktopus/server.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,12 @@ async def _handle_mock_openai(self, request: Request, model: str, messages: List
116116
rule.consume()
117117

118118
# Check if this is an error response
119-
if "error_type" in respond_config:
119+
if respond_config and "error_type" in respond_config:
120120
return await self._handle_error_response(respond_config)
121121

122-
# Extract response config
122+
# Extract response config (handle None case)
123+
if not respond_config:
124+
respond_config = {}
123125
content = respond_config.get("content", "Mocked response")
124126
delay_ms = respond_config.get("delay_ms", 0)
125127
tool_calls = respond_config.get("tool_calls", [])
@@ -241,7 +243,7 @@ async def _handle_error_response(self, error_config: Dict[str, Any]) -> Response
241243
)
242244

243245
async def _stream_openai_response(self, request: Request, content: str, model: str,
244-
tool_calls: List[Dict] = None) -> StreamResponse:
246+
tool_calls: Optional[List[Dict]] = None) -> StreamResponse:
245247
"""Stream OpenAI response using Server-Sent Events"""
246248

247249
response = web.StreamResponse()

0 commit comments

Comments
 (0)