Skip to content

Commit f740531

Browse files
committed
Merge remote-tracking branch 'origin/omni-java' into sync-main-batch-4
# Conflicts: # codeflash/languages/java/instrumentation.py
2 parents d578353 + 4a45ac5 commit f740531

3 files changed

Lines changed: 11 additions & 15 deletions

File tree

codeflash/languages/java/context.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1088,7 +1088,7 @@ def _extract_public_method_signatures(source: str, class_name: str, analyzer: Ja
10881088
sig_parts_bytes.append(mod_slice)
10891089
continue
10901090

1091-
if ctype == "block" or ctype == "constructor_body":
1091+
if ctype in {"block", "constructor_body"}:
10921092
break
10931093

10941094
sig_parts_bytes.append(source_bytes[child.start_byte : child.end_byte])

codeflash/languages/java/instrumentation.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,7 @@ def split_var_declaration(stmt_node, source_bytes_ref: bytes) -> tuple[str, str]
730730
# The variable is assigned inside a for/try block which Java considers
731731
# conditionally executed, so an uninitialized declaration would cause
732732
# "variable might not have been initialized" errors.
733-
_PRIMITIVE_DEFAULTS = {
733+
primitive_defaults = {
734734
"byte": "0",
735735
"short": "0",
736736
"int": "0",
@@ -740,7 +740,7 @@ def split_var_declaration(stmt_node, source_bytes_ref: bytes) -> tuple[str, str]
740740
"char": "'\\0'",
741741
"boolean": "false",
742742
}
743-
default_val = _PRIMITIVE_DEFAULTS.get(type_text, "null")
743+
default_val = primitive_defaults.get(type_text, "null")
744744
hoisted = f"{type_text} {name_text} = {default_val};"
745745
assignment = f"{name_text} = {value_text};"
746746
return hoisted, assignment
@@ -924,9 +924,7 @@ def build_instrumented_body(body_text: str, next_wrapper_id: int, base_indent: s
924924

925925
replacements: list[tuple[int, int, bytes]] = []
926926
wrapper_id = 0
927-
method_ordinal = 0
928-
for method_node, body_node in test_methods:
929-
method_ordinal += 1
927+
for method_ordinal, (method_node, body_node) in enumerate(test_methods, start=1):
930928
body_start = body_node.start_byte + 1 # skip '{'
931929
body_end = body_node.end_byte - 1 # skip '}'
932930
body_text = source_bytes[body_start:body_end].decode("utf8")

codeflash/verification/parse_line_profile_test_output.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,14 @@
66
import json
77
import linecache
88
import os
9-
from typing import TYPE_CHECKING, Optional
9+
from pathlib import Path
10+
from typing import Optional
1011

1112
import dill as pickle
1213

1314
from codeflash.code_utils.tabulate import tabulate
1415
from codeflash.languages import is_python
1516

16-
if TYPE_CHECKING:
17-
from pathlib import Path
18-
1917

2018
def show_func(
2119
filename: str, start_lineno: int, func_name: str, timings: list[tuple[int, int, float]], unit: float
@@ -98,13 +96,13 @@ def show_text_non_python(stats: dict, line_contents: dict[tuple[str, int], str])
9896
table_rows = []
9997
for lineno, nhits, time in timings:
10098
percent = "" if total_time == 0 else "%5.1f" % (100 * time / total_time)
101-
time_disp = "%5.1f" % time
99+
time_disp = f"{time:5.1f}"
102100
if len(time_disp) > default_column_sizes["time"]:
103-
time_disp = "%5.1g" % time
101+
time_disp = f"{time:5.1g}"
104102
perhit = (float(time) / nhits) if nhits > 0 else 0.0
105-
perhit_disp = "%5.1f" % perhit
103+
perhit_disp = f"{perhit:5.1f}"
106104
if len(perhit_disp) > default_column_sizes["perhit"]:
107-
perhit_disp = "%5.1g" % perhit
105+
perhit_disp = f"{perhit:5.1g}"
108106
nhits_disp = "%d" % nhits # noqa: UP031
109107
if len(nhits_disp) > default_column_sizes["hits"]:
110108
nhits_disp = f"{nhits:g}"
@@ -161,7 +159,7 @@ def parse_line_profile_results(line_profiler_output_file: Optional[Path]) -> dic
161159
if not sorted_line_stats:
162160
continue
163161
start_lineno = sorted_line_stats[0][0]
164-
grouped_timings[(file_path, start_lineno, os.path.basename(file_path))] = sorted_line_stats
162+
grouped_timings[(file_path, start_lineno, Path(file_path).name)] = sorted_line_stats
165163

166164
stats_dict["timings"] = grouped_timings
167165
stats_dict["unit"] = 1e-9

0 commit comments

Comments
 (0)