|
3 | 3 | import os |
4 | 4 | from collections import defaultdict |
5 | 5 | from itertools import chain |
6 | | -from pathlib import Path # noqa: TC003 |
| 6 | +from pathlib import Path |
7 | 7 | from typing import TYPE_CHECKING |
8 | 8 |
|
9 | 9 | import libcst as cst |
10 | | -from libcst import CSTNode # noqa: TC002 |
| 10 | +from libcst import CSTNode |
11 | 11 |
|
12 | 12 | from codeflash.cli_cmds.console import logger |
13 | 13 | from codeflash.code_utils.code_extractor import add_needed_imports_from_module, find_preexisting_objects |
14 | 14 | from codeflash.code_utils.code_utils import encoded_tokens_len, get_qualified_name, path_belongs_to_site_packages |
15 | 15 | from codeflash.context.unused_definition_remover import remove_unused_definitions_by_function_names |
16 | | -from codeflash.discovery.functions_to_optimize import FunctionToOptimize # noqa: TC001 |
| 16 | +from codeflash.discovery.functions_to_optimize import FunctionToOptimize |
17 | 17 | from codeflash.models.models import ( |
18 | 18 | CodeContextType, |
19 | 19 | CodeOptimizationContext, |
@@ -150,13 +150,15 @@ def extract_code_string_context_from_files( |
150 | 150 | imports, and combines them. |
151 | 151 |
|
152 | 152 | Args: |
| 153 | + ---- |
153 | 154 | helpers_of_fto: Dictionary mapping file paths to sets of Function Sources of function to optimize and its helpers |
154 | 155 | helpers_of_helpers: Dictionary mapping file paths to sets of Function Sources of helpers of helper functions |
155 | 156 | project_root_path: Root path of the project |
156 | 157 | remove_docstrings: Whether to remove docstrings from the extracted code |
157 | 158 | code_context_type: Type of code context to extract (READ_ONLY, READ_WRITABLE, or TESTGEN) |
158 | 159 |
|
159 | 160 | Returns: |
| 161 | + ------- |
160 | 162 | CodeString containing the extracted code context with necessary imports |
161 | 163 |
|
162 | 164 | """ # noqa: D205 |
@@ -257,13 +259,15 @@ def extract_code_markdown_context_from_files( |
257 | 259 | imports, and combines them into a structured markdown format. |
258 | 260 |
|
259 | 261 | Args: |
| 262 | + ---- |
260 | 263 | helpers_of_fto: Dictionary mapping file paths to sets of Function Sources of function to optimize and its helpers |
261 | 264 | helpers_of_helpers: Dictionary mapping file paths to sets of Function Sources of helpers of helper functions |
262 | 265 | project_root_path: Root path of the project |
263 | 266 | remove_docstrings: Whether to remove docstrings from the extracted code |
264 | 267 | code_context_type: Type of code context to extract (READ_ONLY, READ_WRITABLE, or TESTGEN) |
265 | 268 |
|
266 | 269 | Returns: |
| 270 | + ------- |
267 | 271 | CodeStringsMarkdown containing the extracted code context with necessary imports, |
268 | 272 | formatted for inclusion in markdown |
269 | 273 |
|
@@ -502,7 +506,8 @@ def prune_cst_for_read_writable_code( # noqa: PLR0911 |
502 | 506 | ) -> tuple[cst.CSTNode | None, bool]: |
503 | 507 | """Recursively filter the node and its children to build the read-writable codeblock. This contains nodes that lead to target functions. |
504 | 508 |
|
505 | | - Returns: |
| 509 | + Returns |
| 510 | + ------- |
506 | 511 | (filtered_node, found_target): |
507 | 512 | filtered_node: The modified CST node or None if it should be removed. |
508 | 513 | found_target: True if a target function was found in this node's subtree. |
@@ -586,7 +591,8 @@ def prune_cst_for_read_only_code( # noqa: PLR0911 |
586 | 591 | ) -> tuple[cst.CSTNode | None, bool]: |
587 | 592 | """Recursively filter the node for read-only context. |
588 | 593 |
|
589 | | - Returns: |
| 594 | + Returns |
| 595 | + ------- |
590 | 596 | (filtered_node, found_target): |
591 | 597 | filtered_node: The modified CST node or None if it should be removed. |
592 | 598 | found_target: True if a target function was found in this node's subtree. |
@@ -690,7 +696,8 @@ def prune_cst_for_testgen_code( # noqa: PLR0911 |
690 | 696 | ) -> tuple[cst.CSTNode | None, bool]: |
691 | 697 | """Recursively filter the node for testgen context. |
692 | 698 |
|
693 | | - Returns: |
| 699 | + Returns |
| 700 | + ------- |
694 | 701 | (filtered_node, found_target): |
695 | 702 | filtered_node: The modified CST node or None if it should be removed. |
696 | 703 | found_target: True if a target function was found in this node's subtree. |
|
0 commit comments