Skip to content

Commit 72d9a9e

Browse files
committed
remove ignored linting issues
1 parent d53e6d2 commit 72d9a9e

46 files changed

Lines changed: 172 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: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ def optimize_python_code_line_profiler( # noqa: D417
253253
line_profiler_results: str,
254254
n_candidates: int,
255255
experiment_metadata: ExperimentMetadata | None = None,
256-
is_numerical_code: bool | None = None, # noqa: FBT001
256+
is_numerical_code: bool | None = None,
257257
) -> list[OptimizedCandidate]:
258258
"""Optimize the given python code for performance using line profiler results.
259259
@@ -646,7 +646,7 @@ def generate_regression_tests( # noqa: D417
646646
test_timeout: int,
647647
trace_id: str,
648648
test_index: int,
649-
is_numerical_code: bool | None = None, # noqa: FBT001
649+
is_numerical_code: bool | None = None,
650650
) -> tuple[str, str, str] | None:
651651
"""Generate regression tests for the given function by making a request to the Django endpoint.
652652
@@ -706,7 +706,7 @@ def generate_regression_tests( # noqa: D417
706706
error = response.json()["error"]
707707
logger.error(f"Error generating tests: {response.status_code} - {error}")
708708
ph("cli-testgen-error-response", {"response_status_code": response.status_code, "error": error})
709-
return None # noqa: TRY300
709+
return None
710710
except Exception:
711711
logger.error(f"Error generating tests: {response.status_code} - {response.text}")
712712
ph("cli-testgen-error-response", {"response_status_code": response.status_code, "error": response.text})
@@ -722,7 +722,7 @@ def get_optimization_review(
722722
function_trace_id: str,
723723
coverage_message: str,
724724
replay_tests: str,
725-
concolic_tests: str, # noqa: ARG002
725+
concolic_tests: str,
726726
calling_fn_details: str,
727727
) -> OptimizationReviewResult:
728728
"""Compute the optimization review of current Pull Request.

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().
@@ -376,7 +376,7 @@ def get_blocklisted_functions() -> dict[str, set[str]] | dict[str, Any]:
376376

377377
def is_function_being_optimized_again(
378378
owner: str, repo: str, pr_number: int, code_contexts: list[dict[str, str]]
379-
) -> Any: # noqa: ANN401
379+
) -> Any:
380380
"""Check if the function being optimized is being optimized again."""
381381
response = make_cfapi_request(
382382
"/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: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def get_function_benchmark_timings(trace_path: Path) -> dict[str, dict[Benchmark
110110

111111
# Process each row
112112
for row in cursor.fetchall():
113-
module_name, class_name, function_name, benchmark_file, benchmark_func, benchmark_line, time_ns = row
113+
module_name, class_name, function_name, benchmark_file, benchmark_func, _benchmark_line, time_ns = row
114114

115115
# Create the function key (module_name.class_name.function_name)
116116
if class_name:
@@ -172,7 +172,7 @@ def get_benchmark_timings(trace_path: Path) -> dict[BenchmarkKey, int]:
172172

173173
# Process overhead information
174174
for row in cursor.fetchall():
175-
benchmark_file, benchmark_func, benchmark_line, total_overhead_ns = row
175+
benchmark_file, benchmark_func, _benchmark_line, total_overhead_ns = row
176176
benchmark_key = BenchmarkKey(module_path=benchmark_file, function_name=benchmark_func)
177177
overhead_by_benchmark[benchmark_key] = total_overhead_ns or 0 # Handle NULL sum case
178178

@@ -184,7 +184,7 @@ def get_benchmark_timings(trace_path: Path) -> dict[BenchmarkKey, int]:
184184

185185
# Process each row and subtract overhead
186186
for row in cursor.fetchall():
187-
benchmark_file, benchmark_func, benchmark_line, time_ns = row
187+
benchmark_file, benchmark_func, _benchmark_line, time_ns = row
188188

189189
# Create the benchmark key (file::function::line)
190190
benchmark_key = BenchmarkKey(module_path=benchmark_file, function_name=benchmark_func)
@@ -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:
204204
"""Execute after whole test run is completed."""
205205
# Write any remaining benchmark timings to the database
206206
codeflash_trace.close()
@@ -236,7 +236,7 @@ class Benchmark: # noqa: D106
236236
def __init__(self, request: pytest.FixtureRequest) -> None:
237237
self.request = request
238238

239-
def __call__(self, func, *args, **kwargs): # type: ignore # noqa: ANN001, ANN002, ANN003, ANN204, PGH003
239+
def __call__(self, func, *args, **kwargs): # type: ignore # noqa: ANN002, ANN003, ANN204, PGH003
240240
"""Handle both direct function calls and decorator usage."""
241241
if args or kwargs:
242242
# Used as benchmark(func, *args, **kwargs)
@@ -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: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,7 @@ def create_empty_pyproject_toml(pyproject_toml_path: Path) -> None:
663663
apologize_and_exit()
664664

665665

666-
def install_github_actions(override_formatter_check: bool = False) -> None: # noqa: FBT001, FBT002
666+
def install_github_actions(override_formatter_check: bool = False) -> None:
667667
try:
668668
config, _config_file_path = parse_config_file(override_formatter_check=override_formatter_check)
669669

@@ -1089,7 +1089,7 @@ def install_github_actions(override_formatter_check: bool = False) -> None: # n
10891089
apologize_and_exit()
10901090

10911091

1092-
def determine_dependency_manager(pyproject_data: dict[str, Any]) -> DependencyManager: # noqa: PLR0911
1092+
def determine_dependency_manager(pyproject_data: dict[str, Any]) -> DependencyManager:
10931093
"""Determine which dependency manager is being used based on pyproject.toml contents."""
10941094
if (Path.cwd() / "poetry.lock").exists():
10951095
return DependencyManager.POETRY
@@ -1251,10 +1251,7 @@ def collect_repo_files_for_workflow(git_root: Path) -> dict[str, Any]:
12511251

12521252

12531253
def generate_dynamic_workflow_content(
1254-
optimize_yml_content: str,
1255-
config: tuple[dict[str, Any], Path],
1256-
git_root: Path,
1257-
benchmark_mode: bool = False, # noqa: FBT001, FBT002
1254+
optimize_yml_content: str, config: tuple[dict[str, Any], Path], git_root: Path, benchmark_mode: bool = False
12581255
) -> str:
12591256
"""Generate workflow content with dynamic steps from AI service, falling back to static template.
12601257
@@ -1378,10 +1375,7 @@ def generate_dynamic_workflow_content(
13781375

13791376

13801377
def customize_codeflash_yaml_content(
1381-
optimize_yml_content: str,
1382-
config: tuple[dict[str, Any], Path],
1383-
git_root: Path,
1384-
benchmark_mode: bool = False, # noqa: FBT001, FBT002
1378+
optimize_yml_content: str, config: tuple[dict[str, Any], Path], git_root: Path, benchmark_mode: bool = False
13851379
) -> str:
13861380
module_path = str(Path(config["module_root"]).relative_to(git_root) / "**")
13871381
optimize_yml_content = optimize_yml_content.replace("{{ codeflash_module_path }}", module_path)

codeflash/code_utils/code_extractor.py

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -36,28 +36,28 @@ def __init__(self) -> None:
3636
self.scope_depth = 0
3737
self.if_else_depth = 0
3838

39-
def visit_FunctionDef(self, node: cst.FunctionDef) -> Optional[bool]: # noqa: ARG002
39+
def visit_FunctionDef(self, node: cst.FunctionDef) -> Optional[bool]:
4040
self.scope_depth += 1
4141
return True
4242

43-
def leave_FunctionDef(self, original_node: cst.FunctionDef) -> None: # noqa: ARG002
43+
def leave_FunctionDef(self, original_node: cst.FunctionDef) -> None:
4444
self.scope_depth -= 1
4545

46-
def visit_ClassDef(self, node: cst.ClassDef) -> Optional[bool]: # noqa: ARG002
46+
def visit_ClassDef(self, node: cst.ClassDef) -> Optional[bool]:
4747
self.scope_depth += 1
4848
return True
4949

50-
def leave_ClassDef(self, original_node: cst.ClassDef) -> None: # noqa: ARG002
50+
def leave_ClassDef(self, original_node: cst.ClassDef) -> None:
5151
self.scope_depth -= 1
5252

53-
def visit_If(self, node: cst.If) -> Optional[bool]: # noqa: ARG002
53+
def visit_If(self, node: cst.If) -> Optional[bool]:
5454
self.if_else_depth += 1
5555
return True
5656

57-
def leave_If(self, original_node: cst.If) -> None: # noqa: ARG002
57+
def leave_If(self, original_node: cst.If) -> None:
5858
self.if_else_depth -= 1
5959

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

@@ -111,24 +111,24 @@ def __init__(self, new_assignments: dict[str, cst.Assign], new_assignment_order:
111111
self.scope_depth = 0
112112
self.if_else_depth = 0
113113

114-
def visit_FunctionDef(self, node: cst.FunctionDef) -> None: # noqa: ARG002
114+
def visit_FunctionDef(self, node: cst.FunctionDef) -> None:
115115
self.scope_depth += 1
116116

117-
def leave_FunctionDef(self, original_node: cst.FunctionDef, updated_node: cst.FunctionDef) -> cst.FunctionDef: # noqa: ARG002
117+
def leave_FunctionDef(self, original_node: cst.FunctionDef, updated_node: cst.FunctionDef) -> cst.FunctionDef:
118118
self.scope_depth -= 1
119119
return updated_node
120120

121-
def visit_ClassDef(self, node: cst.ClassDef) -> None: # noqa: ARG002
121+
def visit_ClassDef(self, node: cst.ClassDef) -> None:
122122
self.scope_depth += 1
123123

124-
def leave_ClassDef(self, original_node: cst.ClassDef, updated_node: cst.ClassDef) -> cst.ClassDef: # noqa: ARG002
124+
def leave_ClassDef(self, original_node: cst.ClassDef, updated_node: cst.ClassDef) -> cst.ClassDef:
125125
self.scope_depth -= 1
126126
return updated_node
127127

128-
def visit_If(self, node: cst.If) -> None: # noqa: ARG002
128+
def visit_If(self, node: cst.If) -> None:
129129
self.if_else_depth += 1
130130

131-
def leave_If(self, original_node: cst.If, updated_node: cst.If) -> cst.If: # noqa: ARG002
131+
def leave_If(self, original_node: cst.If, updated_node: cst.If) -> cst.If:
132132
self.if_else_depth -= 1
133133
return updated_node
134134

@@ -150,7 +150,7 @@ def leave_Assign(self, original_node: cst.Assign, updated_node: cst.Assign) -> c
150150

151151
return updated_node
152152

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

@@ -194,20 +194,20 @@ def __init__(self) -> None:
194194
self.global_statements = []
195195
self.in_function_or_class = False
196196

197-
def visit_ClassDef(self, node: cst.ClassDef) -> bool: # noqa: ARG002
197+
def visit_ClassDef(self, node: cst.ClassDef) -> bool:
198198
# Don't visit inside classes
199199
self.in_function_or_class = True
200200
return False
201201

202-
def leave_ClassDef(self, original_node: cst.ClassDef) -> None: # noqa: ARG002
202+
def leave_ClassDef(self, original_node: cst.ClassDef) -> None:
203203
self.in_function_or_class = False
204204

205-
def visit_FunctionDef(self, node: cst.FunctionDef) -> bool: # noqa: ARG002
205+
def visit_FunctionDef(self, node: cst.FunctionDef) -> bool:
206206
# Don't visit inside functions
207207
self.in_function_or_class = True
208208
return False
209209

210-
def leave_FunctionDef(self, original_node: cst.FunctionDef) -> None: # noqa: ARG002
210+
def leave_FunctionDef(self, original_node: cst.FunctionDef) -> None:
211211
self.in_function_or_class = False
212212

213213
def visit_SimpleStatementLine(self, node: cst.SimpleStatementLine) -> None:
@@ -288,16 +288,16 @@ def visit_Module(self, node: cst.Module) -> None:
288288
self.depth = 0
289289
self._collect_imports_from_block(node)
290290

291-
def visit_FunctionDef(self, node: cst.FunctionDef) -> None: # noqa: ARG002
291+
def visit_FunctionDef(self, node: cst.FunctionDef) -> None:
292292
self.depth += 1
293293

294-
def leave_FunctionDef(self, node: cst.FunctionDef) -> None: # noqa: ARG002
294+
def leave_FunctionDef(self, node: cst.FunctionDef) -> None:
295295
self.depth -= 1
296296

297-
def visit_ClassDef(self, node: cst.ClassDef) -> None: # noqa: ARG002
297+
def visit_ClassDef(self, node: cst.ClassDef) -> None:
298298
self.depth += 1
299299

300-
def leave_ClassDef(self, node: cst.ClassDef) -> None: # noqa: ARG002
300+
def leave_ClassDef(self, node: cst.ClassDef) -> None:
301301
self.depth -= 1
302302

303303
def visit_If(self, node: cst.If) -> None:
@@ -320,9 +320,7 @@ def __init__(self, global_statements: list[cst.SimpleStatementLine], last_import
320320
self.inserted = False
321321

322322
def leave_SimpleStatementLine(
323-
self,
324-
original_node: cst.SimpleStatementLine, # noqa: ARG002
325-
updated_node: cst.SimpleStatementLine,
323+
self, original_node: cst.SimpleStatementLine, updated_node: cst.SimpleStatementLine
326324
) -> cst.Module:
327325
self.current_line += 1
328326

@@ -333,7 +331,7 @@ def leave_SimpleStatementLine(
333331

334332
return cst.Module(body=[updated_node])
335333

336-
def leave_Module(self, original_node: cst.Module, updated_node: cst.Module) -> cst.Module: # noqa: ARG002
334+
def leave_Module(self, original_node: cst.Module, updated_node: cst.Module) -> cst.Module:
337335
# If there were no imports, add at the beginning of the module
338336
if self.last_import_line == 0 and not self.inserted:
339337
updated_body = list(updated_node.body)
@@ -361,9 +359,7 @@ def find_last_import_line(target_code: str) -> int:
361359

362360
class FutureAliasedImportTransformer(cst.CSTTransformer):
363361
def leave_ImportFrom(
364-
self,
365-
original_node: cst.ImportFrom, # noqa: ARG002
366-
updated_node: cst.ImportFrom,
362+
self, original_node: cst.ImportFrom, updated_node: cst.ImportFrom
367363
) -> cst.BaseSmallStatement | cst.FlattenSentinel[cst.BaseSmallStatement] | cst.RemovalSentinel:
368364
import libcst.matchers as m
369365

@@ -484,7 +480,7 @@ def resolve_star_import(module_name: str, project_root: Path) -> set[str]:
484480
if not name.startswith("_"):
485481
public_names.add(name)
486482

487-
return public_names # noqa: TRY300
483+
return public_names
488484

489485
except Exception as e:
490486
logger.warning(f"Error resolving star import for {module_name}: {e}")
@@ -973,7 +969,7 @@ def _is_target_function_call(self, node: ast.Call) -> bool:
973969

974970
return False
975971

976-
def _get_call_name(self, func_node) -> Optional[str]: # noqa: ANN001
972+
def _get_call_name(self, func_node) -> Optional[str]:
977973
"""Extract the name being called from a function node."""
978974
# Fast path short-circuit for ast.Name nodes
979975
if isinstance(func_node, ast.Name):
@@ -1363,7 +1359,7 @@ def is_numerical_code(code_string: str, function_name: str | None = None) -> boo
13631359

13641360
# If numba is not installed and all modules used require numba for optimization,
13651361
# return False since we can't optimize this code
1366-
if not has_numba and modules_used.issubset(NUMBA_REQUIRED_MODULES): # noqa : SIM103
1362+
if not has_numba and modules_used.issubset(NUMBA_REQUIRED_MODULES):
13671363
return False
13681364

13691365
return True

0 commit comments

Comments
 (0)