Skip to content

Commit e6ed532

Browse files
authored
Add ruff rules for blind-except (#564)
1 parent fd38097 commit e6ed532

File tree

7 files changed

+26
-25
lines changed

7 files changed

+26
-25
lines changed

examples/evaluation/tru_shared.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import json
2+
import logging
23
import os
34
import uuid
45
from enum import Enum
@@ -28,6 +29,7 @@
2829
load_dotenv()
2930

3031
temperature = 0
32+
logger = logging.getLogger(__name__)
3133

3234

3335
class Framework(Enum):
@@ -223,4 +225,6 @@ def execute_experiment(framework: Framework, pipeline, experiment_name: str):
223225
with tru_recorder:
224226
execute_query(framework, pipeline, query)
225227
except Exception:
226-
print(f"Query: '{query}' caused exception, skipping.")
228+
err = f"Query: '{query}' caused exception, skipping."
229+
logger.exception(err)
230+
print(err)

examples/notebooks/langchain_multimodal_gemini.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@
627627
" \"$vector\": embeddings.image_embedding,\n",
628628
" }\n",
629629
" )\n",
630-
" except Exception as error:\n",
630+
" except Exception as error: # noqa: BLE001\n",
631631
" # if you've already added this record, skip the error message\n",
632632
" error_info = json.loads(str(error))\n",
633633
" if error_info[0][\"errorCode\"] == \"DOCUMENT_ALREADY_EXISTS\":\n",

libs/colbert/ragstack_colbert/cassandra_database.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def _initialize(
9191

9292
try:
9393
is_astra = session.cluster.cloud
94-
except Exception:
94+
except AttributeError:
9595
is_astra = False
9696

9797
logging.info(
@@ -147,7 +147,7 @@ def add_chunks(self, chunks: List[Chunk]) -> List[Tuple[str, int]]:
147147
body_blob=chunk.text,
148148
metadata=chunk.metadata,
149149
)
150-
except Exception as exp:
150+
except Exception as exp: # noqa: BLE001
151151
self._log_insert_error(
152152
doc_id=doc_id, chunk_id=chunk_id, embedding_id=-1, exp=exp
153153
)
@@ -161,7 +161,7 @@ def add_chunks(self, chunks: List[Chunk]) -> List[Tuple[str, int]]:
161161
row_id=(chunk_id, embedding_id),
162162
vector=vector,
163163
)
164-
except Exception as exp:
164+
except Exception as exp: # noqa: BLE001
165165
self._log_insert_error(
166166
doc_id=doc_id, chunk_id=chunk_id, embedding_id=-1, exp=exp
167167
)
@@ -202,7 +202,7 @@ async def _limited_put(
202202
await self._table.aput(
203203
partition_id=doc_id, row_id=row_id, vector=vector
204204
)
205-
except Exception as e:
205+
except Exception as e: # noqa: BLE001
206206
return doc_id, chunk_id, embedding_id, e
207207
return doc_id, chunk_id, embedding_id, None
208208

@@ -317,7 +317,7 @@ async def _limited_delete(
317317
async with sem:
318318
try:
319319
await self._table.adelete_partition(partition_id=doc_id)
320-
except Exception as e:
320+
except Exception as e: # noqa: BLE001
321321
return doc_id, e
322322
return doc_id, None
323323

libs/e2e-tests/e2e_tests/conftest.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,16 +133,16 @@ def pytest_runtest_makereport(item, call):
133133
failed_report_lines.append(report_line)
134134
if call.excinfo:
135135
try:
136-
logging.warn("Full stacktrace:")
136+
logging.warning("Full stacktrace:")
137137
import traceback
138138

139139
traceback.print_exception(
140140
call.excinfo._excinfo[0],
141141
call.excinfo._excinfo[1],
142142
call.excinfo._excinfo[2],
143143
)
144-
except Exception as e:
145-
logging.warn(f"Failed to print stacktrace: {e}")
144+
except Exception: # noqa: BLE001
145+
logging.warning("Failed to print stacktrace", exc_info=True)
146146
all_report_lines.append(report_line)
147147
if is_langchain:
148148
langchain_report_lines.append(report_line)

libs/ragulate/ragstack_ragulate/pipelines/base_pipeline.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import importlib.util
22
import inspect
3-
import traceback
3+
import logging
44
from abc import ABC, abstractmethod
55
from typing import Any, Dict, List
66

77
from ragstack_ragulate.datasets import BaseDataset
88

9-
from ..logging_config import logger
10-
119

1210
# Function to dynamically load a module
1311
def load_module(file_path, name):
@@ -92,13 +90,13 @@ def __init__(
9290
reserved_params=self.get_reserved_params,
9391
passed_ingredients=self._passed_ingredients,
9492
)
95-
except BaseException as e:
96-
logger.fatal(
93+
except BaseException: # noqa: BLE001
94+
logging.critical(
9795
f"Issue loading recipe {self.recipe_name} "
9896
f"on {self.script_path}/{self.method_name} "
99-
f"with passed ingredients: {self._passed_ingredients}: {e}"
97+
f"with passed ingredients: {self._passed_ingredients}",
98+
exc_info=True,
10099
)
101-
traceback.print_exc()
102100
exit(1)
103101

104102
def get_method(self):

libs/ragulate/ragstack_ragulate/pipelines/query_pipeline.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ def stop_evaluation(self, loc: str):
125125
self._tru.stop_evaluator()
126126
self._evaluation_running = False
127127
self._tru.delete_singleton()
128-
except Exception as e:
129-
logger.error(f"issue stopping evaluator: {e}")
128+
except Exception: # noqa: BLE001
129+
logger.exception("issue stopping evaluator")
130130
finally:
131131
self._progress.close()
132132

@@ -218,13 +218,11 @@ def query(self):
218218
try:
219219
with recorder:
220220
pipeline.invoke(query)
221-
except Exception as e:
221+
except Exception as e: # noqa: BLE001
222+
err = f"Query: '{query}' caused exception, skipping."
223+
logger.exception(err)
222224
# TODO: figure out why the logger isn't working after tru-lens starts. For now use print(). # noqa: E501
223-
print(
224-
f"ERROR: Query: '{query}' caused exception, skipping. "
225-
f"Exception {e}"
226-
)
227-
logger.error(f"Query: '{query}' caused exception: {e}, skipping.")
225+
print(f"{err} Exception {e}")
228226
finally:
229227
self.update_progress(query_change=1)
230228

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ ignore = [
6969
select = [
7070
"ASYNC",
7171
"B",
72+
"BLE",
7273
"C4",
7374
"COM",
7475
"DTZ",

0 commit comments

Comments
 (0)