Skip to content

Commit 47ff017

Browse files
committed
inspected fixes
1 parent ff8d477 commit 47ff017

File tree

11 files changed

+25
-25
lines changed

11 files changed

+25
-25
lines changed

codeflash/cli_cmds/cmd_init.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ def determine_dependency_manager(pyproject_data: dict[str, Any]) -> DependencyMa
462462
return DependencyManager.POETRY
463463

464464
# Check for uv
465-
if any(key.startswith("uv") for key in tool_section.keys()):
465+
if any(key.startswith("uv") for key in tool_section):
466466
return DependencyManager.UV
467467

468468
# Look for pip-specific markers
@@ -555,9 +555,8 @@ def customize_codeflash_yaml_content(
555555

556556
# Add codeflash command
557557
codeflash_cmd = get_codeflash_github_action_command(dep_manager)
558-
optimize_yml_content = optimize_yml_content.replace("{{ codeflash_command }}", codeflash_cmd)
558+
return optimize_yml_content.replace("{{ codeflash_command }}", codeflash_cmd)
559559

560-
return optimize_yml_content
561560

562561

563562
# Create or update the pyproject.toml file with the Codeflash dependency & configuration
@@ -596,7 +595,7 @@ def configure_pyproject_toml(setup_info: SetupInfo) -> None:
596595
formatter_cmds.append("disabled")
597596
if formatter in ["black", "ruff"]:
598597
try:
599-
result = subprocess.run([formatter], capture_output=True, check=False)
598+
subprocess.run([formatter], capture_output=True, check=False)
600599
except FileNotFoundError:
601600
click.echo(f"⚠️ Formatter not found: {formatter}, please ensure it is installed")
602601
codeflash_section["formatter-cmds"] = formatter_cmds

codeflash/cli_cmds/console.py

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

33
import logging
4-
from collections.abc import Generator
54
from contextlib import contextmanager
65
from itertools import cycle
76
from typing import TYPE_CHECKING
@@ -14,6 +13,8 @@
1413
from codeflash.cli_cmds.logging_config import BARE_LOGGING_FORMAT
1514

1615
if TYPE_CHECKING:
16+
from collections.abc import Generator
17+
1718
from rich.progress import TaskID
1819

1920
DEBUG_MODE = logging.getLogger().getEffectiveLevel() == logging.DEBUG

codeflash/code_utils/code_replacer.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import ast
44
from collections import defaultdict
55
from functools import lru_cache
6-
from typing import TYPE_CHECKING, TypeVar
6+
from typing import TYPE_CHECKING, Optional, TypeVar
77

88
import libcst as cst
99

@@ -90,10 +90,10 @@ def leave_ClassDef(self, node: cst.ClassDef) -> None:
9090
class OptimFunctionReplacer(cst.CSTTransformer):
9191
def __init__(
9292
self,
93-
modified_functions: dict[tuple[str | None, str], cst.FunctionDef] = None,
94-
new_functions: list[cst.FunctionDef] = None,
95-
new_class_functions: dict[str, list[cst.FunctionDef]] = None,
96-
modified_init_functions: dict[str, cst.FunctionDef] = None,
93+
modified_functions: Optional[dict[tuple[str | None, str], cst.FunctionDef]] = None,
94+
new_functions: Optional[list[cst.FunctionDef]] = None,
95+
new_class_functions: Optional[dict[str, list[cst.FunctionDef]]] = None,
96+
modified_init_functions: Optional[dict[str, cst.FunctionDef]] = None,
9797
) -> None:
9898
super().__init__()
9999
self.modified_functions = modified_functions if modified_functions is not None else {}

codeflash/code_utils/code_utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212

1313
def get_qualified_name(module_name: str, full_qualified_name: str) -> str:
1414
if not full_qualified_name:
15-
raise ValueError("full_qualified_name cannot be empty")
15+
msg = "full_qualified_name cannot be empty"
16+
raise ValueError(msg)
1617
if not full_qualified_name.startswith(module_name):
1718
msg = f"{full_qualified_name} does not start with {module_name}"
1819
raise ValueError(msg)

codeflash/code_utils/concolic_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def _split_top_level_args(self, args_str: str) -> list[str]:
6262

6363
return result
6464

65-
def __init__(self):
65+
def __init__(self) -> None:
6666
# Pre-compiling regular expressions for faster execution
6767
self.assert_re = re.compile(r"\s*assert\s+(.*?)(?:\s*==\s*.*)?$")
6868
self.unittest_re = re.compile(r"(\s*)self\.assert([A-Za-z]+)\((.*)\)$")

codeflash/code_utils/time_utils.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ def humanize_runtime(time_in_ns: int) -> str:
1616

1717
units = re.split(r",|\s", runtime_human)[1]
1818

19-
if units == "microseconds" or units == "microsecond":
20-
runtime_human = "%.3g" % time_micro
21-
elif units == "milliseconds" or units == "millisecond":
19+
if units in ("microseconds", "microsecond"):
20+
runtime_human = f"{time_micro:.3g}"
21+
elif units in ("milliseconds", "millisecond"):
2222
runtime_human = "%.3g" % (time_micro / 1000)
23-
elif units == "seconds" or units == "second":
23+
elif units in ("seconds", "second"):
2424
runtime_human = "%.3g" % (time_micro / (1000**2))
25-
elif units == "minutes" or units == "minute":
25+
elif units in ("minutes", "minute"):
2626
runtime_human = "%.3g" % (time_micro / (60 * 1000**2))
2727
else: # hours
2828
runtime_human = "%.3g" % (time_micro / (3600 * 1000**2))

codeflash/discovery/discover_unit_tests.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ def discover_tests_pytest(
5959
],
6060
cwd=project_root,
6161
check=False,
62-
stdout=subprocess.PIPE,
63-
stderr=subprocess.PIPE,
62+
capture_output=True,
6463
text=True,
6564
)
6665
try:

codeflash/optimization/function_optimizer.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ def optimize_function(self) -> Result[BestOptimization, str]:
243243

244244
best_optimization = None
245245

246-
for u, candidates in enumerate([optimizations_set.control, optimizations_set.experiment]):
246+
for _u, candidates in enumerate([optimizations_set.control, optimizations_set.experiment]):
247247
if candidates is None:
248248
continue
249249

@@ -1088,7 +1088,8 @@ def run_and_parse_tests(
10881088
test_framework=self.test_cfg.test_framework,
10891089
)
10901090
else:
1091-
raise ValueError(f"Unexpected testing type: {testing_type}")
1091+
msg = f"Unexpected testing type: {testing_type}"
1092+
raise ValueError(msg)
10921093
except subprocess.TimeoutExpired:
10931094
logger.exception(
10941095
f"Error running tests in {', '.join(str(f) for f in test_files.test_files)}.\nTimeout Error"

codeflash/result/explanation.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def to_console_string(self) -> str:
3838
original_runtime_human = humanize_runtime(self.original_runtime_ns)
3939
best_runtime_human = humanize_runtime(self.best_runtime_ns)
4040

41-
explanation = (
41+
return (
4242
f"Optimized {self.function_name} in {self.file_path}\n"
4343
f"{self.perf_improvement_line}\n"
4444
f"Runtime went down from {original_runtime_human} to {best_runtime_human} \n\n"
@@ -49,7 +49,6 @@ def to_console_string(self) -> str:
4949
+ f"{TestResults.report_to_string(self.winning_behavioral_test_results.get_test_pass_fail_report_by_type())}\n"
5050
)
5151

52-
return explanation
5352

5453
def explanation_message(self) -> str:
5554
return self.raw_explanation_message

codeflash/telemetry/sentry.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from sentry_sdk.integrations.logging import LoggingIntegration
55

66

7-
def init_sentry(enabled: bool = False, exclude_errors: bool = False):
7+
def init_sentry(enabled: bool = False, exclude_errors: bool = False) -> None:
88
if enabled:
99
sentry_logging = LoggingIntegration(
1010
level=logging.INFO, # Capture info and above as breadcrumbs

0 commit comments

Comments
 (0)