Skip to content

Commit 8879e2e

Browse files
committed
blocklisted funcs bugfix
1 parent af1f078 commit 8879e2e

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

codeflash/discovery/functions_to_optimize.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
import ast
4+
import json
45
import os
56
import random
67
import warnings
@@ -156,9 +157,9 @@ def get_functions_to_optimize(
156157
project_root: Path,
157158
module_root: Path,
158159
) -> tuple[dict[Path, list[FunctionToOptimize]], int]:
159-
assert (
160-
sum([bool(optimize_all), bool(replay_test), bool(file)]) <= 1
161-
), "Only one of optimize_all, replay_test, or file should be provided"
160+
assert sum([bool(optimize_all), bool(replay_test), bool(file)]) <= 1, (
161+
"Only one of optimize_all, replay_test, or file should be provided"
162+
)
162163
functions: dict[str, list[FunctionToOptimize]]
163164
with warnings.catch_warnings():
164165
warnings.simplefilter(action="ignore", category=SyntaxWarning)
@@ -434,9 +435,7 @@ def filter_functions(
434435
test_functions_removed_count += len(functions)
435436
continue
436437
if file_path in ignore_paths or any(
437-
# file_path.startswith(ignore_path + os.sep) for ignore_path in ignore_paths if ignore_path
438-
file_path.startswith(str(ignore_path) + os.sep)
439-
for ignore_path in ignore_paths
438+
file_path.startswith(str(ignore_path) + os.sep) for ignore_path in ignore_paths
440439
):
441440
ignore_paths_removed_count += 1
442441
continue
@@ -457,15 +456,17 @@ def filter_functions(
457456
malformed_paths_count += 1
458457
continue
459458
if blocklist_funcs:
460-
for function in functions.copy():
461-
path = Path(function.file_path).name
462-
if path in blocklist_funcs and function.function_name in blocklist_funcs[path]:
463-
functions.remove(function)
464-
logger.debug(f"Skipping {function.function_name} in {path} as it has already been optimized")
465-
continue
466-
459+
functions = [
460+
function
461+
for function in functions
462+
if not (
463+
Path(function.file_path).name in blocklist_funcs
464+
and function.qualified_name in blocklist_funcs[Path(function.file_path).name]
465+
)
466+
]
467467
filtered_modified_functions[file_path] = functions
468468
functions_count += len(functions)
469+
469470
if not disable_logs:
470471
log_info = {
471472
f"{test_functions_removed_count} test function{'s' if test_functions_removed_count != 1 else ''}": test_functions_removed_count,
@@ -475,10 +476,11 @@ def filter_functions(
475476
f"{ignore_paths_removed_count} file{'s' if ignore_paths_removed_count != 1 else ''} from ignored paths": ignore_paths_removed_count,
476477
f"{submodule_ignored_paths_count} file{'s' if submodule_ignored_paths_count != 1 else ''} from ignored submodules": submodule_ignored_paths_count,
477478
}
478-
log_string: str
479-
if log_string := "\n".join([k for k, v in log_info.items() if v > 0]):
479+
log_string = "\n".join([k for k, v in log_info.items() if v > 0])
480+
if log_string:
480481
logger.info(f"Ignoring: {log_string}")
481482
console.rule()
483+
482484
return {Path(k): v for k, v in filtered_modified_functions.items() if v}, functions_count
483485

484486

0 commit comments

Comments
 (0)