Skip to content

Commit ea48939

Browse files
style: auto-fix linting and formatting issues
1 parent 7c7eeb5 commit ea48939

6 files changed

Lines changed: 53 additions & 46 deletions

File tree

codeflash/cli_cmds/console.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,16 @@
4040

4141
logging.basicConfig(
4242
level=logging.INFO,
43-
handlers=[RichHandler(rich_tracebacks=True, markup=False, highlighter=NullHighlighter(), console=console, show_path=False, show_time=False)],
43+
handlers=[
44+
RichHandler(
45+
rich_tracebacks=True,
46+
markup=False,
47+
highlighter=NullHighlighter(),
48+
console=console,
49+
show_path=False,
50+
show_time=False,
51+
)
52+
],
4453
format=BARE_LOGGING_FORMAT,
4554
)
4655

codeflash/cli_cmds/logging_config.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,16 @@ def set_level(level: int, *, echo_setting: bool = True) -> None:
1414

1515
logging.basicConfig(
1616
level=level,
17-
handlers=[RichHandler(rich_tracebacks=True, markup=False, highlighter=NullHighlighter(), console=console, show_path=False, show_time=False)],
17+
handlers=[
18+
RichHandler(
19+
rich_tracebacks=True,
20+
markup=False,
21+
highlighter=NullHighlighter(),
22+
console=console,
23+
show_path=False,
24+
show_time=False,
25+
)
26+
],
1827
format=BARE_LOGGING_FORMAT,
1928
)
2029
logging.getLogger().setLevel(level)
@@ -23,7 +32,14 @@ def set_level(level: int, *, echo_setting: bool = True) -> None:
2332
logging.basicConfig(
2433
format=VERBOSE_LOGGING_FORMAT,
2534
handlers=[
26-
RichHandler(rich_tracebacks=True, markup=False, highlighter=NullHighlighter(), console=console, show_path=False, show_time=False)
35+
RichHandler(
36+
rich_tracebacks=True,
37+
markup=False,
38+
highlighter=NullHighlighter(),
39+
console=console,
40+
show_path=False,
41+
show_time=False,
42+
)
2743
],
2844
force=True,
2945
)

codeflash/languages/java/context.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -887,11 +887,7 @@ def collect_type_identifiers(node: Node) -> None:
887887

888888

889889
def get_java_imported_type_skeletons(
890-
imports: list,
891-
project_root: Path,
892-
module_root: Path | None,
893-
analyzer: JavaAnalyzer,
894-
target_code: str = "",
890+
imports: list, project_root: Path, module_root: Path | None, analyzer: JavaAnalyzer, target_code: str = ""
895891
) -> str:
896892
"""Extract type skeletons for project-internal imported types.
897893
@@ -1011,9 +1007,7 @@ def _extract_constructor_summaries(skeleton: TypeSkeleton) -> list[str]:
10111007
return summaries
10121008

10131009

1014-
def _format_skeleton_for_context(
1015-
skeleton: TypeSkeleton, source: str, class_name: str, analyzer: JavaAnalyzer
1016-
) -> str:
1010+
def _format_skeleton_for_context(skeleton: TypeSkeleton, source: str, class_name: str, analyzer: JavaAnalyzer) -> str:
10171011
"""Format a TypeSkeleton into a context string with method signatures.
10181012
10191013
Includes: type declaration, fields, constructors, and public method signatures
@@ -1094,7 +1088,7 @@ def _extract_public_method_signatures(source: str, class_name: str, analyzer: Ja
10941088
sig_parts_bytes.append(mod_slice)
10951089
continue
10961090

1097-
if ctype == "block" or ctype == "constructor_body":
1091+
if ctype in {"block", "constructor_body"}:
10981092
break
10991093

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

codeflash/languages/java/instrumentation.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -730,11 +730,17 @@ 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 = {
734-
"byte": "0", "short": "0", "int": "0", "long": "0L",
735-
"float": "0.0f", "double": "0.0", "char": "'\\0'", "boolean": "false",
733+
primitive_defaults = {
734+
"byte": "0",
735+
"short": "0",
736+
"int": "0",
737+
"long": "0L",
738+
"float": "0.0f",
739+
"double": "0.0",
740+
"char": "'\\0'",
741+
"boolean": "false",
736742
}
737-
default_val = _PRIMITIVE_DEFAULTS.get(type_text, "null")
743+
default_val = primitive_defaults.get(type_text, "null")
738744
hoisted = f"{type_text} {name_text} = {default_val};"
739745
assignment = f"{name_text} = {value_text};"
740746
return hoisted, assignment
@@ -918,9 +924,7 @@ def build_instrumented_body(body_text: str, next_wrapper_id: int, base_indent: s
918924

919925
replacements: list[tuple[int, int, bytes]] = []
920926
wrapper_id = 0
921-
method_ordinal = 0
922-
for method_node, body_node in test_methods:
923-
method_ordinal += 1
927+
for method_ordinal, (method_node, body_node) in enumerate(test_methods, start=1):
924928
body_start = body_node.start_byte + 1 # skip '{'
925929
body_end = body_node.end_byte - 1 # skip '}'
926930
body_text = source_bytes[body_start:body_end].decode("utf8")

codeflash/languages/java/replacement.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -374,13 +374,7 @@ def replace_function(
374374
class_name,
375375
)
376376
source = _insert_class_members(
377-
source,
378-
class_name,
379-
new_fields_to_add,
380-
new_helpers_before,
381-
new_helpers_after,
382-
func_name,
383-
analyzer,
377+
source, class_name, new_fields_to_add, new_helpers_before, new_helpers_after, func_name, analyzer
384378
)
385379

386380
# Re-find the target method after modifications

codeflash/verification/parse_line_profile_test_output.py

Lines changed: 10 additions & 20 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
@@ -80,9 +78,7 @@ def show_text(stats: dict) -> str:
8078
return out_table
8179

8280

83-
def show_text_non_python(
84-
stats: dict, line_contents: dict[tuple[str, int], str]
85-
) -> str:
81+
def show_text_non_python(stats: dict, line_contents: dict[tuple[str, int], str]) -> str:
8682
"""Show text for non-Python timings using profiler-provided line contents."""
8783
out_table = ""
8884
out_table += "# Timer unit: {:g} s\n".format(stats["unit"])
@@ -100,13 +96,13 @@ def show_text_non_python(
10096
table_rows = []
10197
for lineno, nhits, time in timings:
10298
percent = "" if total_time == 0 else "%5.1f" % (100 * time / total_time)
103-
time_disp = "%5.1f" % time
99+
time_disp = f"{time:5.1f}"
104100
if len(time_disp) > default_column_sizes["time"]:
105-
time_disp = "%5.1g" % time
101+
time_disp = f"{time:5.1g}"
106102
perhit = (float(time) / nhits) if nhits > 0 else 0.0
107-
perhit_disp = "%5.1f" % perhit
103+
perhit_disp = f"{perhit:5.1f}"
108104
if len(perhit_disp) > default_column_sizes["perhit"]:
109-
perhit_disp = "%5.1g" % perhit
105+
perhit_disp = f"{perhit:5.1g}"
110106
nhits_disp = "%d" % nhits # noqa: UP031
111107
if len(nhits_disp) > default_column_sizes["hits"]:
112108
nhits_disp = f"{nhits:g}"
@@ -115,11 +111,7 @@ def show_text_non_python(
115111

116112
table_cols = ("Hits", "Time", "Per Hit", "% Time", "Line Contents")
117113
out_table += tabulate(
118-
headers=table_cols,
119-
tabular_data=table_rows,
120-
tablefmt="pipe",
121-
colglobalalign=None,
122-
preserve_whitespace=True,
114+
headers=table_cols, tabular_data=table_rows, tablefmt="pipe", colglobalalign=None, preserve_whitespace=True
123115
)
124116
out_table += "\n"
125117
return out_table
@@ -159,17 +151,15 @@ def parse_line_profile_results(line_profiler_output_file: Optional[Path]) -> dic
159151
line_num = int(line_str)
160152
line_num = int(line_num)
161153

162-
lines_by_file.setdefault(file_path, []).append(
163-
(line_num, int(stats.get("hits", 0)), int(stats.get("time", 0)))
164-
)
154+
lines_by_file.setdefault(file_path, []).append((line_num, int(stats.get("hits", 0)), int(stats.get("time", 0))))
165155
line_contents[(file_path, line_num)] = stats.get("content", "")
166156

167157
for file_path, line_stats in lines_by_file.items():
168158
sorted_line_stats = sorted(line_stats, key=lambda t: t[0])
169159
if not sorted_line_stats:
170160
continue
171161
start_lineno = sorted_line_stats[0][0]
172-
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
173163

174164
stats_dict["timings"] = grouped_timings
175165
stats_dict["unit"] = 1e-9

0 commit comments

Comments
 (0)