Skip to content

Commit 84d0b1c

Browse files
committed
Merge branch 'main' into multi-language
2 parents a29f877 + d12553c commit 84d0b1c

45 files changed

Lines changed: 156 additions & 194 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

codeflash/api/aiservice.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ def optimize_python_code_line_profiler(
298298
line_profiler_results: str,
299299
n_candidates: int,
300300
experiment_metadata: ExperimentMetadata | None = None,
301-
is_numerical_code: bool | None = None, # noqa: FBT001
301+
is_numerical_code: bool | None = None,
302302
language: str = "python",
303303
language_version: str | None = None,
304304
) -> list[OptimizedCandidate]:
@@ -814,7 +814,7 @@ def generate_regression_tests(
814814
error = response.json()["error"]
815815
logger.error(f"Error generating tests: {response.status_code} - {error}")
816816
ph("cli-testgen-error-response", {"response_status_code": response.status_code, "error": error})
817-
return None # noqa: TRY300
817+
return None
818818
except Exception:
819819
logger.error(f"Error generating tests: {response.status_code} - {response.text}")
820820
ph("cli-testgen-error-response", {"response_status_code": response.status_code, "error": response.text})
@@ -830,7 +830,6 @@ def get_optimization_review(
830830
function_trace_id: str,
831831
coverage_message: str,
832832
replay_tests: str,
833-
concolic_tests: str, # noqa: ARG002
834833
calling_fn_details: str,
835834
language: str = "python",
836835
) -> OptimizationReviewResult:

codeflash/api/cfapi.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def make_cfapi_request(
8181
else:
8282
response = requests.get(url, headers=cfapi_headers, params=params, timeout=60)
8383
response.raise_for_status()
84-
return response # noqa: TRY300
84+
return response
8585
except requests.exceptions.HTTPError:
8686
# response may be either a string or JSON, so we handle both cases
8787
error_message = ""
@@ -102,7 +102,7 @@ def make_cfapi_request(
102102

103103

104104
@lru_cache(maxsize=1)
105-
def get_user_id(api_key: Optional[str] = None) -> Optional[str]: # noqa: PLR0911
105+
def get_user_id(api_key: Optional[str] = None) -> Optional[str]:
106106
"""Retrieve the user's userid by making a request to the /cfapi/cli-get-user endpoint.
107107
108108
:param api_key: The API key to use. If None, uses get_codeflash_api_key().
@@ -396,7 +396,7 @@ def get_blocklisted_functions() -> dict[str, set[str]] | dict[str, Any]:
396396

397397
def is_function_being_optimized_again(
398398
owner: str, repo: str, pr_number: int, code_contexts: list[dict[str, str]]
399-
) -> Any: # noqa: ANN401
399+
) -> Any:
400400
"""Check if the function being optimized is being optimized again."""
401401
response = make_cfapi_request(
402402
"/is-already-optimized",

codeflash/benchmarking/codeflash_trace.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def __call__(self, func: Callable) -> Callable:
108108
func_id = (func.__module__, func.__name__)
109109

110110
@functools.wraps(func)
111-
def wrapper(*args, **kwargs) -> Any: # noqa: ANN002, ANN003, ANN401
111+
def wrapper(*args, **kwargs) -> Any: # noqa: ANN002, ANN003
112112
# Initialize thread-local active functions set if it doesn't exist
113113
if not hasattr(self._thread_local, "active_functions"):
114114
self._thread_local.active_functions = set()

codeflash/benchmarking/instrument_codeflash_trace.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def leave_FunctionDef(self, original_node: FunctionDef, updated_node: FunctionDe
5353

5454
return updated_node
5555

56-
def leave_Module(self, original_node: cst.Module, updated_node: cst.Module) -> cst.Module: # noqa: ARG002
56+
def leave_Module(self, original_node: cst.Module, updated_node: cst.Module) -> cst.Module:
5757
# Create import statement for codeflash_trace
5858
if not self.added_codeflash_trace:
5959
return updated_node

codeflash/benchmarking/plugin/plugin.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ def get_benchmark_timings(trace_path: Path) -> dict[BenchmarkKey, int]:
200200

201201
# Pytest hooks
202202
@pytest.hookimpl
203-
def pytest_sessionfinish(self, session, exitstatus) -> None: # noqa: ANN001, ARG002
203+
def pytest_sessionfinish(self, session, exitstatus) -> None: # noqa: ANN001
204204
"""Execute after whole test run is completed."""
205205
# Write any remaining benchmark timings to the database
206206
codeflash_trace.close()
@@ -218,7 +218,7 @@ def pytest_collection_modifyitems(config: pytest.Config, items: list[pytest.Item
218218
skip_no_benchmark = pytest.mark.skip(reason="Test requires benchmark fixture")
219219
for item in items:
220220
# Check for direct benchmark fixture usage
221-
has_fixture = hasattr(item, "fixturenames") and "benchmark" in item.fixturenames
221+
has_fixture = hasattr(item, "fixturenames") and "benchmark" in item.fixturenames # ty:ignore[unsupported-operator]
222222

223223
# Check for @pytest.mark.benchmark marker
224224
has_marker = False
@@ -249,7 +249,7 @@ def wrapped_func(*args, **kwargs): # noqa: ANN002, ANN003, ANN202
249249
self._run_benchmark(func)
250250
return wrapped_func
251251

252-
def _run_benchmark(self, func, *args, **kwargs): # noqa: ANN001, ANN002, ANN003, ANN202
252+
def _run_benchmark(self, func, *args, **kwargs): # noqa: ANN002, ANN003, ANN202
253253
"""Actual benchmark implementation."""
254254
node_path = getattr(self.request.node, "path", None) or getattr(self.request.node, "fspath", None)
255255
if node_path is None:

codeflash/cli_cmds/cli_common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def inquirer_wrapper(func: Callable[..., str | bool], *args: str | bool, **kwarg
4343
return func(*new_args, **new_kwargs)
4444

4545

46-
def split_string_to_cli_width(string: str, is_confirm: bool = False) -> list[str]: # noqa: FBT001, FBT002
46+
def split_string_to_cli_width(string: str, is_confirm: bool = False) -> list[str]:
4747
cli_width, _ = shutil.get_terminal_size()
4848
# split string to lines that accommodate "[?] " prefix
4949
cli_width -= len("[?] ")

codeflash/cli_cmds/cmd_init.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@ def create_empty_pyproject_toml(pyproject_toml_path: Path) -> None:
687687
apologize_and_exit()
688688

689689

690-
def install_github_actions(override_formatter_check: bool = False) -> None: # noqa: FBT001, FBT002
690+
def install_github_actions(override_formatter_check: bool = False) -> None:
691691
try:
692692
config, _config_file_path = parse_config_file(override_formatter_check=override_formatter_check)
693693

@@ -1121,11 +1121,12 @@ def install_github_actions(override_formatter_check: bool = False) -> None: # n
11211121
apologize_and_exit()
11221122

11231123

1124-
def determine_dependency_manager(pyproject_data: dict[str, Any]) -> DependencyManager: # noqa: PLR0911
1124+
def determine_dependency_manager(pyproject_data: dict[str, Any]) -> DependencyManager:
11251125
"""Determine which dependency manager is being used based on pyproject.toml contents."""
1126-
if (Path.cwd() / "poetry.lock").exists():
1126+
cwd = Path.cwd()
1127+
if (cwd / "poetry.lock").exists():
11271128
return DependencyManager.POETRY
1128-
if (Path.cwd() / "uv.lock").exists():
1129+
if (cwd / "uv.lock").exists():
11291130
return DependencyManager.UV
11301131
if "tool" not in pyproject_data:
11311132
return DependencyManager.PIP
@@ -1325,10 +1326,7 @@ def collect_repo_files_for_workflow(git_root: Path) -> dict[str, Any]:
13251326

13261327

13271328
def generate_dynamic_workflow_content(
1328-
optimize_yml_content: str,
1329-
config: tuple[dict[str, Any], Path],
1330-
git_root: Path,
1331-
benchmark_mode: bool = False, # noqa: FBT001, FBT002
1329+
optimize_yml_content: str, config: tuple[dict[str, Any], Path], git_root: Path, benchmark_mode: bool = False
13321330
) -> str:
13331331
"""Generate workflow content with dynamic steps from AI service, falling back to static template.
13341332
@@ -1460,10 +1458,7 @@ def generate_dynamic_workflow_content(
14601458

14611459

14621460
def customize_codeflash_yaml_content(
1463-
optimize_yml_content: str,
1464-
config: tuple[dict[str, Any], Path],
1465-
git_root: Path,
1466-
benchmark_mode: bool = False, # noqa: FBT001, FBT002
1461+
optimize_yml_content: str, config: tuple[dict[str, Any], Path], git_root: Path, benchmark_mode: bool = False
14671462
) -> str:
14681463
module_path = str(Path(config["module_root"]).relative_to(git_root) / "**")
14691464
optimize_yml_content = optimize_yml_content.replace("{{ codeflash_module_path }}", module_path)

codeflash/code_utils/code_extractor.py

Lines changed: 34 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@ def visit_FunctionDef(self, node: cst.FunctionDef) -> Optional[bool]:
4545
self.scope_depth += 1
4646
return True
4747

48-
def leave_FunctionDef(self, original_node: cst.FunctionDef) -> None: # noqa: ARG002
48+
def leave_FunctionDef(self, original_node: cst.FunctionDef) -> None:
4949
self.scope_depth -= 1
5050

51-
def visit_ClassDef(self, node: cst.ClassDef) -> Optional[bool]: # noqa: ARG002
51+
def visit_ClassDef(self, node: cst.ClassDef) -> Optional[bool]:
5252
self.scope_depth += 1
5353
return True
5454

55-
def leave_ClassDef(self, original_node: cst.ClassDef) -> None: # noqa: ARG002
55+
def leave_ClassDef(self, original_node: cst.ClassDef) -> None:
5656
self.scope_depth -= 1
5757

5858

@@ -66,7 +66,7 @@ def __init__(self, new_functions: dict[str, cst.FunctionDef], new_function_order
6666
self.processed_functions: set[str] = set()
6767
self.scope_depth = 0
6868

69-
def visit_FunctionDef(self, node: cst.FunctionDef) -> None: # noqa: ARG002
69+
def visit_FunctionDef(self, node: cst.FunctionDef) -> None:
7070
self.scope_depth += 1
7171

7272
def leave_FunctionDef(self, original_node: cst.FunctionDef, updated_node: cst.FunctionDef) -> cst.FunctionDef:
@@ -81,14 +81,14 @@ def leave_FunctionDef(self, original_node: cst.FunctionDef, updated_node: cst.Fu
8181
return self.new_functions[name]
8282
return updated_node
8383

84-
def visit_ClassDef(self, node: cst.ClassDef) -> None: # noqa: ARG002
84+
def visit_ClassDef(self, node: cst.ClassDef) -> None:
8585
self.scope_depth += 1
8686

87-
def leave_ClassDef(self, original_node: cst.ClassDef, updated_node: cst.ClassDef) -> cst.ClassDef: # noqa: ARG002
87+
def leave_ClassDef(self, original_node: cst.ClassDef, updated_node: cst.ClassDef) -> cst.ClassDef:
8888
self.scope_depth -= 1
8989
return updated_node
9090

91-
def leave_Module(self, original_node: cst.Module, updated_node: cst.Module) -> cst.Module: # noqa: ARG002
91+
def leave_Module(self, original_node: cst.Module, updated_node: cst.Module) -> cst.Module:
9292
# Add any new functions that weren't in the original file
9393
new_statements = list(updated_node.body)
9494

@@ -142,28 +142,28 @@ def __init__(self) -> None:
142142
self.scope_depth = 0
143143
self.if_else_depth = 0
144144

145-
def visit_FunctionDef(self, node: cst.FunctionDef) -> Optional[bool]: # noqa: ARG002
145+
def visit_FunctionDef(self, node: cst.FunctionDef) -> Optional[bool]:
146146
self.scope_depth += 1
147147
return True
148148

149-
def leave_FunctionDef(self, original_node: cst.FunctionDef) -> None: # noqa: ARG002
149+
def leave_FunctionDef(self, original_node: cst.FunctionDef) -> None:
150150
self.scope_depth -= 1
151151

152-
def visit_ClassDef(self, node: cst.ClassDef) -> Optional[bool]: # noqa: ARG002
152+
def visit_ClassDef(self, node: cst.ClassDef) -> Optional[bool]:
153153
self.scope_depth += 1
154154
return True
155155

156-
def leave_ClassDef(self, original_node: cst.ClassDef) -> None: # noqa: ARG002
156+
def leave_ClassDef(self, original_node: cst.ClassDef) -> None:
157157
self.scope_depth -= 1
158158

159-
def visit_If(self, node: cst.If) -> Optional[bool]: # noqa: ARG002
159+
def visit_If(self, node: cst.If) -> Optional[bool]:
160160
self.if_else_depth += 1
161161
return True
162162

163-
def leave_If(self, original_node: cst.If) -> None: # noqa: ARG002
163+
def leave_If(self, original_node: cst.If) -> None:
164164
self.if_else_depth -= 1
165165

166-
def visit_Else(self, node: cst.Else) -> Optional[bool]: # noqa: ARG002
166+
def visit_Else(self, node: cst.Else) -> Optional[bool]:
167167
# Else blocks are already counted as part of the if statement
168168
return True
169169

@@ -232,24 +232,24 @@ def __init__(self, new_assignments: dict[str, cst.Assign | cst.AnnAssign], new_a
232232
self.scope_depth = 0
233233
self.if_else_depth = 0
234234

235-
def visit_FunctionDef(self, node: cst.FunctionDef) -> None: # noqa: ARG002
235+
def visit_FunctionDef(self, node: cst.FunctionDef) -> None:
236236
self.scope_depth += 1
237237

238-
def leave_FunctionDef(self, original_node: cst.FunctionDef, updated_node: cst.FunctionDef) -> cst.FunctionDef: # noqa: ARG002
238+
def leave_FunctionDef(self, original_node: cst.FunctionDef, updated_node: cst.FunctionDef) -> cst.FunctionDef:
239239
self.scope_depth -= 1
240240
return updated_node
241241

242-
def visit_ClassDef(self, node: cst.ClassDef) -> None: # noqa: ARG002
242+
def visit_ClassDef(self, node: cst.ClassDef) -> None:
243243
self.scope_depth += 1
244244

245-
def leave_ClassDef(self, original_node: cst.ClassDef, updated_node: cst.ClassDef) -> cst.ClassDef: # noqa: ARG002
245+
def leave_ClassDef(self, original_node: cst.ClassDef, updated_node: cst.ClassDef) -> cst.ClassDef:
246246
self.scope_depth -= 1
247247
return updated_node
248248

249-
def visit_If(self, node: cst.If) -> None: # noqa: ARG002
249+
def visit_If(self, node: cst.If) -> None:
250250
self.if_else_depth += 1
251251

252-
def leave_If(self, original_node: cst.If, updated_node: cst.If) -> cst.If: # noqa: ARG002
252+
def leave_If(self, original_node: cst.If, updated_node: cst.If) -> cst.If:
253253
self.if_else_depth -= 1
254254
return updated_node
255255

@@ -284,7 +284,7 @@ def leave_AnnAssign(self, original_node: cst.AnnAssign, updated_node: cst.AnnAss
284284

285285
return updated_node
286286

287-
def leave_Module(self, original_node: cst.Module, updated_node: cst.Module) -> cst.Module: # noqa: ARG002
287+
def leave_Module(self, original_node: cst.Module, updated_node: cst.Module) -> cst.Module:
288288
# Add any new assignments that weren't in the original file
289289
new_statements = list(updated_node.body)
290290

@@ -371,7 +371,7 @@ def __init__(self, global_statements: list[cst.SimpleStatementLine]) -> None:
371371
super().__init__()
372372
self.global_statements = global_statements
373373

374-
def leave_Module(self, original_node: cst.Module, updated_node: cst.Module) -> cst.Module: # noqa: ARG002
374+
def leave_Module(self, original_node: cst.Module, updated_node: cst.Module) -> cst.Module:
375375
if not self.global_statements:
376376
return updated_node
377377

@@ -397,20 +397,20 @@ def __init__(self) -> None:
397397
self.global_statements = []
398398
self.in_function_or_class = False
399399

400-
def visit_ClassDef(self, node: cst.ClassDef) -> bool: # noqa: ARG002
400+
def visit_ClassDef(self, node: cst.ClassDef) -> bool:
401401
# Don't visit inside classes
402402
self.in_function_or_class = True
403403
return False
404404

405-
def leave_ClassDef(self, original_node: cst.ClassDef) -> None: # noqa: ARG002
405+
def leave_ClassDef(self, original_node: cst.ClassDef) -> None:
406406
self.in_function_or_class = False
407407

408-
def visit_FunctionDef(self, node: cst.FunctionDef) -> bool: # noqa: ARG002
408+
def visit_FunctionDef(self, node: cst.FunctionDef) -> bool:
409409
# Don't visit inside functions
410410
self.in_function_or_class = True
411411
return False
412412

413-
def leave_FunctionDef(self, original_node: cst.FunctionDef) -> None: # noqa: ARG002
413+
def leave_FunctionDef(self, original_node: cst.FunctionDef) -> None:
414414
self.in_function_or_class = False
415415

416416
def visit_SimpleStatementLine(self, node: cst.SimpleStatementLine) -> None:
@@ -491,16 +491,16 @@ def visit_Module(self, node: cst.Module) -> None:
491491
self.depth = 0
492492
self._collect_imports_from_block(node)
493493

494-
def visit_FunctionDef(self, node: cst.FunctionDef) -> None: # noqa: ARG002
494+
def visit_FunctionDef(self, node: cst.FunctionDef) -> None:
495495
self.depth += 1
496496

497-
def leave_FunctionDef(self, node: cst.FunctionDef) -> None: # noqa: ARG002
497+
def leave_FunctionDef(self, node: cst.FunctionDef) -> None:
498498
self.depth -= 1
499499

500-
def visit_ClassDef(self, node: cst.ClassDef) -> None: # noqa: ARG002
500+
def visit_ClassDef(self, node: cst.ClassDef) -> None:
501501
self.depth += 1
502502

503-
def leave_ClassDef(self, node: cst.ClassDef) -> None: # noqa: ARG002
503+
def leave_ClassDef(self, node: cst.ClassDef) -> None:
504504
self.depth -= 1
505505

506506
def visit_If(self, node: cst.If) -> None:
@@ -530,9 +530,7 @@ def find_last_import_line(target_code: str) -> int:
530530

531531
class FutureAliasedImportTransformer(cst.CSTTransformer):
532532
def leave_ImportFrom(
533-
self,
534-
original_node: cst.ImportFrom, # noqa: ARG002
535-
updated_node: cst.ImportFrom,
533+
self, original_node: cst.ImportFrom, updated_node: cst.ImportFrom
536534
) -> cst.BaseSmallStatement | cst.FlattenSentinel[cst.BaseSmallStatement] | cst.RemovalSentinel:
537535
import libcst.matchers as m
538536

@@ -677,7 +675,7 @@ def resolve_star_import(module_name: str, project_root: Path) -> set[str]:
677675
if not name.startswith("_"):
678676
public_names.add(name)
679677

680-
return public_names # noqa: TRY300
678+
return public_names
681679

682680
except Exception as e:
683681
logger.warning(f"Error resolving star import for {module_name}: {e}")
@@ -1166,7 +1164,7 @@ def _is_target_function_call(self, node: ast.Call) -> bool:
11661164

11671165
return False
11681166

1169-
def _get_call_name(self, func_node) -> Optional[str]: # noqa: ANN001
1167+
def _get_call_name(self, func_node) -> Optional[str]:
11701168
"""Extract the name being called from a function node."""
11711169
# Fast path short-circuit for ast.Name nodes
11721170
if isinstance(func_node, ast.Name):
@@ -1559,10 +1557,7 @@ def is_numerical_code(code_string: str, function_name: str | None = None) -> boo
15591557

15601558
# If numba is not installed and all modules used require numba for optimization,
15611559
# return False since we can't optimize this code
1562-
if not has_numba and modules_used.issubset(NUMBA_REQUIRED_MODULES): # noqa : SIM103
1563-
return False
1564-
1565-
return True
1560+
return not (not has_numba and modules_used.issubset(NUMBA_REQUIRED_MODULES))
15661561

15671562

15681563
def get_opt_review_metrics(

codeflash/code_utils/code_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def filter_args(addopts_args: list[str]) -> list[str]:
166166
return filtered_args
167167

168168

169-
def modify_addopts(config_file: Path) -> tuple[str, bool]: # noqa : PLR0911
169+
def modify_addopts(config_file: Path) -> tuple[str, bool]:
170170
file_type = config_file.suffix.lower()
171171
filename = config_file.name
172172
config = None

0 commit comments

Comments
 (0)