Skip to content

Commit dbea741

Browse files
fix linter errors
1 parent fae940d commit dbea741

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

codeflash/api/cfapi.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -131,17 +131,21 @@ def validate_api_key(api_key: Optional[str] = None) -> None:
131131
# First check if API key exists
132132
if not api_key:
133133
api_key = get_codeflash_api_key()
134-
134+
135+
def raise_os_error(msg: str) -> None:
136+
"""Raise OSError with the given message."""
137+
raise OSError(msg)
138+
135139
# Make the request to validate the API key
136140
try:
137141
response = make_cfapi_request(
138-
endpoint="/cli-get-user",
139-
method="GET",
140-
extra_headers={"cli_version": __version__},
142+
endpoint="/cli-get-user",
143+
method="GET",
144+
extra_headers={"cli_version": __version__},
141145
api_key=api_key,
142-
suppress_errors=True # Don't log errors yet, we'll handle it below
146+
suppress_errors=True, # Don't log errors yet, we'll handle it below
143147
)
144-
148+
145149
if response.status_code == 403:
146150
msg = (
147151
"Invalid Codeflash API key. The API key you provided is not valid.\n"
@@ -150,27 +154,27 @@ def validate_api_key(api_key: Optional[str] = None) -> None:
150154
"For more information, refer to the documentation at "
151155
"https://docs.codeflash.ai/getting-started/codeflash-github-actions#add-your-api-key-to-your-repository-secrets."
152156
)
153-
raise OSError(msg)
157+
raise_os_error(msg)
154158
elif response.status_code != 200:
155159
msg = (
156160
f"Failed to validate API key with Codeflash API (status {response.status_code}).\n"
157161
"Please verify your API key is correct.\n"
158162
"You can generate a new one at https://app.codeflash.ai/app/apikeys"
159163
)
160-
raise OSError(msg)
161-
164+
raise_os_error(msg)
165+
162166
# Check for version updates
163167
if response.status_code == 200:
164168
try:
165169
resp_json = response.json()
166170
min_version = resp_json.get("min_version")
167171
if min_version and version.parse(min_version) > version.parse(__version__):
168172
msg = "Your Codeflash CLI version is outdated. Please update to the latest version using `pip install --upgrade codeflash`."
169-
raise OSError(msg)
173+
raise_os_error(msg)
170174
except (json.JSONDecodeError, KeyError, TypeError):
171175
# If response is not JSON or doesn't have min_version, that's okay
172176
pass
173-
177+
174178
except OSError:
175179
# Re-raise OSError as-is
176180
raise

codeflash/optimization/optimizer.py

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

33
import ast
4+
import contextlib
45
import copy
56
import os
67
import tempfile
@@ -507,10 +508,8 @@ def run_with_args(args: Namespace) -> None:
507508
# Log the error if we have an optimizer instance with cleanup
508509
if optimizer:
509510
logger.error(f"Error during optimization: {e}")
510-
try:
511+
with contextlib.suppress(Exception):
511512
optimizer.cleanup_temporary_paths()
512-
except Exception:
513-
pass
514513
else:
515514
logger.error(f"Error initializing optimizer: {e}")
516515
raise

0 commit comments

Comments
 (0)