Skip to content

Commit f6b3275

Browse files
committed
fix mypy types
1 parent e2f1ba0 commit f6b3275

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

codeflash/api/cfapi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ def get_blocklisted_functions() -> dict[str, set[str]] | dict[str, Any]:
196196

197197
def is_function_being_optimized_again(
198198
owner: str, repo: str, pr_number: int, code_contexts: list[dict[str, str]]
199-
) -> dict:
199+
) -> Any: # noqa: ANN401
200200
"""Check if the function being optimized is being optimized again."""
201201
response = make_cfapi_request(
202202
"/is-already-optimized",

codeflash/context/code_context_extractor.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import os
55
from collections import defaultdict
66
from itertools import chain
7-
from typing import TYPE_CHECKING
7+
from typing import TYPE_CHECKING, cast
88

99
import libcst as cst
1010

@@ -625,20 +625,24 @@ def prune_cst_for_code_hashing( # noqa: PLR0911
625625
if not isinstance(node.body, cst.IndentedBlock):
626626
raise ValueError("ClassDef body is not an IndentedBlock") # noqa: TRY004
627627
class_prefix = f"{prefix}.{node.name.value}" if prefix else node.name.value
628-
new_body = []
628+
new_class_body: list[cst.CSTNode] = []
629629
found_target = False
630630

631631
for stmt in node.body.body:
632632
if isinstance(stmt, cst.FunctionDef):
633633
qualified_name = f"{class_prefix}.{stmt.name.value}"
634634
if qualified_name in target_functions:
635-
stmt_with_changes = stmt.with_changes(body=remove_docstring_from_body(stmt.body))
636-
new_body.append(stmt_with_changes)
635+
stmt_with_changes = stmt.with_changes(
636+
body=remove_docstring_from_body(cast("cst.IndentedBlock", stmt.body))
637+
)
638+
new_class_body.append(stmt_with_changes)
637639
found_target = True
638640
# If no target functions found, remove the class entirely
639-
if not new_body or not found_target:
641+
if not new_class_body or not found_target:
640642
return None, False
641-
return node.with_changes(body=cst.IndentedBlock(new_body)) if new_body else None, found_target
643+
return node.with_changes(
644+
body=cst.IndentedBlock(cast("list[cst.BaseStatement]", new_class_body))
645+
) if new_class_body else None, found_target
642646

643647
# For other nodes, we preserve them only if they contain target functions in their children.
644648
section_names = get_section_names(node)

0 commit comments

Comments
 (0)