Skip to content

Commit 535c640

Browse files
fix: resolve all linting issues from ruff and mypy
Fixed ruff issues: - PLW0108: Removed unnecessary lambda wrappers, inline method references - Changed lambda: self.future_all_code_repair.clear() to self.future_all_code_repair.clear - Changed lambda: self.future_adaptive_optimizations.clear() to self.future_adaptive_optimizations.clear - PTH123: Replaced open() with Path.open() for debug file - S108: Use get_run_tmp_file() instead of hardcoded /tmp path for security - RUF059: Prefix unused concolic_tests variable with underscore Fixed mypy issues in PrComment.py: - Renamed loop variable from 'result' to 'test_result' to avoid redefinition - Removed str() conversion for async throughput values (already int type) - Type annotations now match actual value types All files formatted with ruff format. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent bab3bd4 commit 535c640

2 files changed

Lines changed: 13 additions & 18 deletions

File tree

codeflash/github/PrComment.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ class PrComment:
2626

2727
def to_json(self) -> dict[str, Union[str, int, dict[str, dict[str, int]], list[BenchmarkDetail], None]]:
2828
report_table: dict[str, dict[str, int]] = {}
29-
for test_type, result in self.winning_behavior_test_results.get_test_pass_fail_report_by_type().items():
29+
for test_type, test_result in self.winning_behavior_test_results.get_test_pass_fail_report_by_type().items():
3030
name = test_type.to_name()
3131
if name:
32-
report_table[name] = result
32+
report_table[name] = test_result
3333

3434
result: dict[str, Union[str, int, dict[str, dict[str, int]], list[BenchmarkDetail], None]] = {
3535
"optimization_explanation": self.optimization_explanation,
@@ -45,8 +45,8 @@ def to_json(self) -> dict[str, Union[str, int, dict[str, dict[str, int]], list[B
4545
}
4646

4747
if self.original_async_throughput is not None and self.best_async_throughput is not None:
48-
result["original_async_throughput"] = str(self.original_async_throughput)
49-
result["best_async_throughput"] = str(self.best_async_throughput)
48+
result["original_async_throughput"] = self.original_async_throughput
49+
result["best_async_throughput"] = self.best_async_throughput
5050

5151
return result
5252

codeflash/optimization/function_optimizer.py

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -311,14 +311,12 @@ def _handle_empty_queue(self) -> CandidateNode | None:
311311
lambda: setattr(self, "line_profiler_done", True),
312312
)
313313
if len(self.future_all_code_repair) > 0:
314-
result = self._process_candidates(
314+
return self._process_candidates(
315315
self.future_all_code_repair,
316316
"Repairing {0} candidates",
317317
"Added {0} candidates from repair, total candidates now: {1}",
318-
None,
318+
self.future_all_code_repair.clear,
319319
)
320-
self.future_all_code_repair.clear()
321-
return result
322320
if self.line_profiler_done and not self.refinement_done:
323321
return self._process_candidates(
324322
self.future_all_refinements,
@@ -328,14 +326,12 @@ def _handle_empty_queue(self) -> CandidateNode | None:
328326
filter_candidates_func=self._filter_refined_candidates,
329327
)
330328
if len(self.future_adaptive_optimizations) > 0:
331-
result = self._process_candidates(
329+
return self._process_candidates(
332330
self.future_adaptive_optimizations,
333331
"Applying adaptive optimizations to {0} candidates",
334332
"Added {0} candidates from adaptive optimization, total candidates now: {1}",
335-
None,
333+
self.future_adaptive_optimizations.clear,
336334
)
337-
self.future_adaptive_optimizations.clear()
338-
return result
339335
return None # All done
340336

341337
def _process_candidates(
@@ -600,11 +596,10 @@ def generate_and_instrument_tests(
600596
logger.debug(f"[PIPELINE] Wrote behavioral test to {generated_test.behavior_file_path}")
601597

602598
# Save perf test source for debugging
603-
from pathlib import Path
604-
605-
debug_path = Path("/tmp/codeflash_perf_test_debug.test.ts") # noqa: S108
606-
debug_path.write_text(generated_test.instrumented_perf_test_source, encoding="utf-8")
607-
logger.warning("[PERF DEBUG] Saved perf test to /tmp/codeflash_perf_test_debug.test.ts for inspection")
599+
debug_file_path = get_run_tmp_file(Path("perf_test_debug.test.ts"))
600+
with debug_file_path.open("w", encoding="utf-8") as debug_f:
601+
debug_f.write(generated_test.instrumented_perf_test_source)
602+
logger.warning(f"[PERF DEBUG] Saved perf test to {debug_file_path} for inspection")
608603

609604
with generated_test.perf_file_path.open("w", encoding="utf8") as f:
610605
f.write(generated_test.instrumented_perf_test_source)
@@ -2104,7 +2099,7 @@ def process_review(
21042099
formatted_generated_test = format_generated_code(concolic_test_str, self.args.formatter_cmds)
21052100
generated_tests_str += f"```{code_lang}\n{formatted_generated_test}\n```\n\n"
21062101

2107-
existing_tests, replay_tests, _ = existing_tests_source_for(
2102+
existing_tests, replay_tests, _concolic_tests = existing_tests_source_for(
21082103
self.function_to_optimize.qualified_name_with_modules_from_root(self.project_root),
21092104
function_to_all_tests,
21102105
test_cfg=self.test_cfg,

0 commit comments

Comments
 (0)