Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions codeflash/code_utils/shell_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,10 @@ def get_cross_platform_subprocess_run_args(
capture_output: bool = True,
) -> dict[str, str]:
run_args = {"cwd": cwd, "env": env, "text": text, "timeout": timeout, "check": check}
# When text=True, use errors='replace' to handle non-UTF-8 bytes gracefully
# instead of raising UnicodeDecodeError
if text:
run_args["errors"] = "replace"
if sys.platform == "win32":
creationflags = subprocess.CREATE_NEW_PROCESS_GROUP
run_args["creationflags"] = creationflags
Expand Down
8 changes: 4 additions & 4 deletions codeflash/github/PrComment.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def to_json(self) -> dict[str, Union[str, int, dict[str, dict[str, int]], list[B
if name:
report_table[name] = result

result: dict[str, Union[str, int, dict[str, dict[str, int]], list[BenchmarkDetail], None]] = {
result: dict[str, Union[str, int, dict[str, dict[str, int]], list[BenchmarkDetail], None]] = { # type: ignore[no-redef]
"optimization_explanation": self.optimization_explanation,
"best_runtime": humanize_runtime(self.best_runtime),
"original_runtime": humanize_runtime(self.original_runtime),
Expand All @@ -45,10 +45,10 @@ def to_json(self) -> dict[str, Union[str, int, dict[str, dict[str, int]], list[B
}

if self.original_async_throughput is not None and self.best_async_throughput is not None:
result["original_async_throughput"] = str(self.original_async_throughput)
result["best_async_throughput"] = str(self.best_async_throughput)
result["original_async_throughput"] = str(self.original_async_throughput) # type: ignore[assignment]
result["best_async_throughput"] = str(self.best_async_throughput) # type: ignore[assignment]

return result
return result # type: ignore[return-value]


class FileDiffContent(BaseModel):
Expand Down
4 changes: 2 additions & 2 deletions codeflash/languages/javascript/find_references.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def find_references(
trigger_check = True
if import_info:
context.visited_files.add(file_path)
import_name, original_import = import_info
import_name, original_import = import_info # noqa: RUF059
file_refs = self._find_references_in_file(
file_path, file_code, reexport_name, import_name, file_analyzer, include_self=True
)
Expand Down Expand Up @@ -404,7 +404,7 @@ def _find_identifier_references(
name_node = node.child_by_field_name("name")
if name_node:
new_current_function = source_bytes[name_node.start_byte : name_node.end_byte].decode("utf8")
elif node.type in ("variable_declarator",):
elif node.type in ("variable_declarator",): # noqa: FURB171
# Arrow function or function expression assigned to variable
name_node = node.child_by_field_name("name")
value_node = node.child_by_field_name("value")
Expand Down
7 changes: 1 addition & 6 deletions codeflash/languages/javascript/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,7 @@
from junitparser.xunit2 import JUnitXml

from codeflash.cli_cmds.console import logger
from codeflash.models.models import (
FunctionTestInvocation,
InvocationId,
TestResults,
TestType,
)
from codeflash.models.models import FunctionTestInvocation, InvocationId, TestResults, TestType

if TYPE_CHECKING:
import subprocess
Expand Down
3 changes: 1 addition & 2 deletions codeflash/languages/javascript/vitest_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,7 @@ def run_vitest_behavioral_tests(
logger.debug(f"Vitest JUnit XML created: {result_file_path} ({file_size} bytes)")
if file_size < 200: # Suspiciously small - likely empty or just headers
logger.warning(
f"Vitest JUnit XML is very small ({file_size} bytes). "
f"Content: {result_file_path.read_text()[:500]}"
f"Vitest JUnit XML is very small ({file_size} bytes). Content: {result_file_path.read_text()[:500]}"
)
else:
logger.warning(
Expand Down
4 changes: 2 additions & 2 deletions codeflash/languages/treesitter_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1580,9 +1580,9 @@ def get_analyzer_for_file(file_path: Path) -> TreeSitterAnalyzer:
"""
suffix = file_path.suffix.lower()

if suffix in (".ts",):
if suffix in (".ts",): # noqa: FURB171
return TreeSitterAnalyzer(TreeSitterLanguage.TYPESCRIPT)
if suffix in (".tsx",):
if suffix in (".tsx",): # noqa: FURB171
return TreeSitterAnalyzer(TreeSitterLanguage.TSX)
# Default to JavaScript for .js, .jsx, .mjs, .cjs
return TreeSitterAnalyzer(TreeSitterLanguage.JAVASCRIPT)
6 changes: 3 additions & 3 deletions codeflash/optimization/function_optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ def _handle_empty_queue(self) -> CandidateNode | None:
self.future_all_code_repair,
"Repairing {0} candidates",
"Added {0} candidates from repair, total candidates now: {1}",
lambda: self.future_all_code_repair.clear(),
lambda: self.future_all_code_repair.clear(), # noqa: PLW0108
)
if self.line_profiler_done and not self.refinement_done:
return self._process_candidates(
Expand All @@ -330,7 +330,7 @@ def _handle_empty_queue(self) -> CandidateNode | None:
self.future_adaptive_optimizations,
"Applying adaptive optimizations to {0} candidates",
"Added {0} candidates from adaptive optimization, total candidates now: {1}",
lambda: self.future_adaptive_optimizations.clear(),
lambda: self.future_adaptive_optimizations.clear(), # noqa: PLW0108
)
return None # All done

Expand Down Expand Up @@ -2093,7 +2093,7 @@ def process_review(
formatted_generated_test = format_generated_code(concolic_test_str, self.args.formatter_cmds)
generated_tests_str += f"```{code_lang}\n{formatted_generated_test}\n```\n\n"

existing_tests, replay_tests, concolic_tests = existing_tests_source_for(
existing_tests, replay_tests, concolic_tests = existing_tests_source_for( # noqa: RUF059
self.function_to_optimize.qualified_name_with_modules_from_root(self.project_root),
function_to_all_tests,
test_cfg=self.test_cfg,
Expand Down
Loading