Skip to content

Commit 06d16b4

Browse files
github-actions[bot]claude
authored andcommitted
fix: resolve mypy type errors in JavaScript tracer
- Add explicit type annotations for json.load return values - Annotate result dict with dict[str, Any] - Add type hints for config parameters - Fix pytest_split unpacking to satisfy type checker - Add null check for outfile before passing to run_javascript_tracer_main Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent f4e6df7 commit 06d16b4

3 files changed

Lines changed: 17 additions & 11 deletions

File tree

codeflash/languages/javascript/tracer.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ def parse_results(trace_file: Path) -> list[dict[str, Any]]:
8080
if json_file.exists():
8181
try:
8282
with json_file.open("r") as f:
83-
return json.load(f)
83+
data: list[dict[str, Any]] = json.load(f)
84+
return data
8485
except Exception as e:
8586
logger.exception("Failed to parse trace JSON: %s", e)
8687
return []

codeflash/languages/javascript/tracer_runner.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def run_javascript_tracer(args: Namespace, config: dict[str, Any], project_root:
9999
- error: Error message (if failed)
100100
101101
"""
102-
result = {"success": False, "trace_file": None, "replay_test_file": None, "error": None}
102+
result: dict[str, Any] = {"success": False, "trace_file": None, "replay_test_file": None, "error": None}
103103

104104
# Find Node.js
105105
node_path = find_node_executable()
@@ -260,7 +260,8 @@ def detect_test_framework(project_root: Path, config: dict[str, Any]) -> str:
260260
"""
261261
# Check config first
262262
if "test_framework" in config:
263-
return config["test_framework"]
263+
framework: str = config["test_framework"]
264+
return framework
264265

265266
# Check for vitest config files
266267
vitest_configs = ["vitest.config.js", "vitest.config.ts", "vitest.config.mjs"]

codeflash/tracer.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
from argparse import Namespace
3333

3434

35-
def detect_language_from_config(config: dict) -> str:
35+
def detect_language_from_config(config: dict[str, Any]) -> str:
3636
"""Detect the project language from config or file extensions.
3737
3838
Args:
@@ -44,7 +44,8 @@ def detect_language_from_config(config: dict) -> str:
4444
"""
4545
# Check explicit language in config
4646
if "language" in config:
47-
return config["language"].lower()
47+
language: str = config["language"].lower()
48+
return language
4849

4950
# Check module root for file types
5051
module_root = Path(config.get("module_root", "."))
@@ -138,6 +139,8 @@ def main(args: Namespace | None = None) -> ArgumentParser:
138139

139140
# Route to appropriate tracer based on language
140141
if language in ("javascript", "typescript"):
142+
if outfile is None:
143+
outfile = Path("codeflash.trace.sqlite")
141144
return run_javascript_tracer_main(parsed_args, config, project_root, outfile, unknown_args)
142145

143146
if len(unknown_args) > 0:
@@ -152,16 +155,17 @@ def main(args: Namespace | None = None) -> ArgumentParser:
152155
"module": parsed_args.module,
153156
}
154157
try:
155-
pytest_splits = []
156-
test_paths = []
157-
replay_test_paths = []
158+
pytest_splits: list[list[str]] = []
159+
test_paths: list[str] = []
160+
replay_test_paths: list[str] = []
158161
if parsed_args.module and unknown_args[0] == "pytest":
159-
pytest_splits, test_paths = pytest_split(unknown_args[1:], limit=parsed_args.limit)
160-
if pytest_splits is None or test_paths is None:
162+
split_result = pytest_split(unknown_args[1:], limit=parsed_args.limit)
163+
if split_result[0] is None or split_result[1] is None:
161164
console.print(f"❌ Could not find test files in the specified paths: {unknown_args[1:]}")
162165
console.print(f"Current working directory: {Path.cwd()}")
163166
console.print("Please ensure the test directory exists and contains test files.")
164167
sys.exit(1)
168+
pytest_splits, test_paths = split_result
165169

166170
if len(pytest_splits) > 1:
167171
processes = []
@@ -303,7 +307,7 @@ def main(args: Namespace | None = None) -> ArgumentParser:
303307

304308

305309
def run_javascript_tracer_main(
306-
parsed_args: Namespace, config: dict, project_root: Path, outfile: Path, unknown_args: list[str]
310+
parsed_args: Namespace, config: dict[str, Any], project_root: Path, outfile: Path, unknown_args: list[str]
307311
) -> ArgumentParser:
308312
"""Run the JavaScript tracer.
309313

0 commit comments

Comments
 (0)