Skip to content

Commit d74b3f5

Browse files
committed
refactor: use contextlib.suppress and add logging for optimization check
- Replace try/except/pass with contextlib.suppress for cleaner code - Add warning log when API call fails to check optimization status
1 parent 8d25bd5 commit d74b3f5

1 file changed

Lines changed: 6 additions & 7 deletions

File tree

codeflash/discovery/functions_to_optimize.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141

4242
from codeflash.models.models import CodeOptimizationContext
4343
from codeflash.verification.verification_utils import TestConfig
44+
import contextlib
45+
4446
from rich.text import Text
4547

4648
_property_id = "property"
@@ -804,11 +806,9 @@ def was_function_previously_optimized(
804806
# already_optimized_count = 0
805807
owner = None
806808
repo = None
807-
try:
809+
with contextlib.suppress(git.exc.InvalidGitRepositoryError):
808810
owner, repo = get_repo_owner_and_name()
809-
except git.exc.InvalidGitRepositoryError:
810-
pass
811-
811+
812812
pr_number = get_pr_number()
813813

814814
if not owner or not repo or pr_number is None or getattr(args, "no_pr", False):
@@ -824,14 +824,13 @@ def was_function_previously_optimized(
824824
}
825825
]
826826

827-
828827
try:
829828
result = is_function_being_optimized_again(owner, repo, pr_number, code_contexts)
830829
already_optimized_paths: list[tuple[str, str]] = result.get("already_optimized_tuples", [])
831830
return len(already_optimized_paths) > 0
832831

833-
except Exception:
834-
# Return all functions if API call fails
832+
except Exception as e:
833+
logger.warning(f"Failed to check optimization status: {e}")
835834
# Return all functions if API call fails
836835
return False
837836

0 commit comments

Comments
 (0)