Skip to content

Commit bde6e06

Browse files
committed
pre-commit run
1 parent b942040 commit bde6e06

File tree

4 files changed

+35
-27
lines changed

4 files changed

+35
-27
lines changed

codeflash/code_utils/edit_generated_tests.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def add_runtime_comments_to_generated_tests(
4141
optimized_runtime_by_test = optimized_test_results.usable_runtime_data_by_test_case()
4242

4343
class RuntimeCommentTransformer(cst.CSTTransformer):
44-
def __init__(self):
44+
def __init__(self) -> None:
4545
self.in_test_function = False
4646
self.current_test_name = None
4747

@@ -60,7 +60,9 @@ def leave_FunctionDef(self, original_node: cst.FunctionDef, updated_node: cst.Fu
6060
return updated_node
6161

6262
def leave_SimpleStatementLine(
63-
self, original_node: cst.SimpleStatementLine, updated_node: cst.SimpleStatementLine
63+
self,
64+
original_node: cst.SimpleStatementLine, # noqa: ARG002
65+
updated_node: cst.SimpleStatementLine,
6466
) -> cst.SimpleStatementLine:
6567
if not self.in_test_function or not self.current_test_name:
6668
return updated_node
@@ -69,14 +71,13 @@ def leave_SimpleStatementLine(
6971
# Handle both single statements and multiple statements on one line
7072
codeflash_assignment_found = False
7173
for stmt in updated_node.body:
72-
if isinstance(stmt, cst.Assign):
73-
if (
74-
len(stmt.targets) == 1
75-
and isinstance(stmt.targets[0].target, cst.Name)
76-
and stmt.targets[0].target.value == "codeflash_output"
77-
):
78-
codeflash_assignment_found = True
79-
break
74+
if isinstance(stmt, cst.Assign) and (
75+
len(stmt.targets) == 1
76+
and isinstance(stmt.targets[0].target, cst.Name)
77+
and stmt.targets[0].target.value == "codeflash_output"
78+
):
79+
codeflash_assignment_found = True
80+
break
8081

8182
if codeflash_assignment_found:
8283
# Find matching test cases by looking for this test function name in the test results

codeflash/code_utils/time_utils.py

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -66,25 +66,31 @@ def format_with_precision(value: float, unit: str) -> str:
6666
return f"{value:.1f}{unit}"
6767
return f"{value:.2f}{unit}"
6868

69+
result = ""
6970
if nanoseconds < 1_000:
70-
return f"{nanoseconds}ns"
71-
if nanoseconds < 1_000_000:
71+
result = f"{nanoseconds}ns"
72+
elif nanoseconds < 1_000_000:
7273
# Convert to microseconds
7374
microseconds_int = nanoseconds // 1_000
7475
if count_significant_digits(microseconds_int) >= 3:
75-
return f"{microseconds_int}μs"
76-
microseconds_float = nanoseconds / 1_000
77-
return format_with_precision(microseconds_float, "μs")
78-
if nanoseconds < 1_000_000_000:
76+
result = f"{microseconds_int}μs"
77+
else:
78+
microseconds_float = nanoseconds / 1_000
79+
result = format_with_precision(microseconds_float, "μs")
80+
elif nanoseconds < 1_000_000_000:
7981
# Convert to milliseconds
8082
milliseconds_int = nanoseconds // 1_000_000
8183
if count_significant_digits(milliseconds_int) >= 3:
82-
return f"{milliseconds_int}ms"
83-
milliseconds_float = nanoseconds / 1_000_000
84-
return format_with_precision(milliseconds_float, "ms")
85-
# Convert to seconds
86-
seconds_int = nanoseconds // 1_000_000_000
87-
if count_significant_digits(seconds_int) >= 3:
88-
return f"{seconds_int}s"
89-
seconds_float = nanoseconds / 1_000_000_000
90-
return format_with_precision(seconds_float, "s")
84+
result = f"{milliseconds_int}ms"
85+
else:
86+
milliseconds_float = nanoseconds / 1_000_000
87+
result = format_with_precision(milliseconds_float, "ms")
88+
else:
89+
# Convert to seconds
90+
seconds_int = nanoseconds // 1_000_000_000
91+
if count_significant_digits(seconds_int) >= 3:
92+
result = f"{seconds_int}s"
93+
else:
94+
seconds_float = nanoseconds / 1_000_000_000
95+
result = format_with_precision(seconds_float, "s")
96+
return result

codeflash/context/code_context_extractor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ def get_function_to_optimize_as_function_source(
386386
source_code=name.get_line_code(),
387387
jedi_definition=name,
388388
)
389-
except Exception as e: # noqa: PERF203
389+
except Exception as e:
390390
logger.exception(f"Error while getting function source: {e}")
391391
continue
392392
raise ValueError(

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,8 @@ ignore = [
191191
"T201",
192192
"PGH004",
193193
"S301",
194-
"D104"
194+
"D104",
195+
"PERF203"
195196
]
196197

197198
[tool.ruff.lint.flake8-type-checking]

0 commit comments

Comments
 (0)