Skip to content

Commit 20c9034

Browse files
authored
Add ruff rules for bugbear (#551)
1 parent 18f565f commit 20c9034

File tree

9 files changed

+22
-25
lines changed

9 files changed

+22
-25
lines changed

libs/colbert/ragstack_colbert/cassandra_database.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,8 @@ async def _limited_put(
183183
text: Optional[str] = None,
184184
metadata: Optional[Dict[str, Any]] = None,
185185
vector: Optional[Vector] = None,
186-
) -> Tuple[str, int, int, Exception]:
186+
) -> Tuple[str, int, int, Optional[Exception]]:
187187
row_id = (chunk_id, embedding_id)
188-
exp = None
189188
async with sem:
190189
try:
191190
if vector is None:
@@ -199,10 +198,9 @@ async def _limited_put(
199198
await self._table.aput(
200199
partition_id=doc_id, row_id=row_id, vector=vector
201200
)
201+
return doc_id, chunk_id, embedding_id, None
202202
except Exception as e:
203-
exp = e
204-
finally:
205-
return doc_id, chunk_id, embedding_id, exp
203+
return doc_id, chunk_id, embedding_id, e
206204

207205
async def aadd_chunks(
208206
self, chunks: List[Chunk], concurrent_inserts: Optional[int] = 100
@@ -311,15 +309,13 @@ async def _limited_delete(
311309
self,
312310
sem: asyncio.Semaphore,
313311
doc_id: str,
314-
) -> Tuple[str, Exception]:
315-
exp = None
312+
) -> Tuple[str, Optional[Exception]]:
316313
async with sem:
317314
try:
318315
await self._table.adelete_partition(partition_id=doc_id)
316+
return doc_id, None
319317
except Exception as e:
320-
exp = e
321-
finally:
322-
return doc_id, exp
318+
return doc_id, e
323319

324320
async def adelete_chunks(
325321
self, doc_ids: List[str], concurrent_deletes: Optional[int] = 100

libs/e2e-tests/e2e_tests/test_utils/vector_store_handler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,4 @@ def before_test(self) -> VectorStoreTestContext:
6767
pass
6868

6969
def after_test(self):
70-
pass
70+
return

libs/knowledge-graph/ragstack_knowledge_graph/cassandra_graph_store.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def add_graph_documents(
5454
self.graph.insert(_elements(graph_documents))
5555

5656
# TODO: should this include the types of each node?
57-
def query(self, query: str, params: dict = {}) -> List[Dict[str, Any]]:
57+
def query(self, query: str, params: dict = {}) -> List[Dict[str, Any]]: # noqa: B006
5858
raise ValueError("Querying Cassandra should use `as_runnable`.")
5959

6060
@property

libs/langchain/ragstack_langchain/colbert/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
try:
22
from ragstack_colbert.base_retriever import BaseRetriever # noqa
3-
except (ImportError, ModuleNotFoundError):
3+
except (ImportError, ModuleNotFoundError) as e:
44
raise ImportError(
55
"Could not import ragstack-ai-colbert. "
66
"Please install it with `pip install ragstack-ai-langchain[colbert]`."
7-
)
7+
) from e
88

99
from .colbert_retriever import ColbertRetriever
1010
from .colbert_vector_store import ColbertVectorStore

libs/langchain/ragstack_langchain/graph_store/base.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,13 @@ def _texts_to_nodes(
5959
for text in texts:
6060
try:
6161
_metadata = next(metadatas_it).copy() if metadatas_it else {}
62-
except StopIteration:
63-
raise ValueError("texts iterable longer than metadatas")
62+
except StopIteration as e:
63+
raise ValueError("texts iterable longer than metadatas") from e
6464
try:
6565
_id = next(ids_it) if ids_it else None
6666
_id = _id or _metadata.pop(METADATA_CONTENT_ID_KEY, None)
67-
except StopIteration:
68-
raise ValueError("texts iterable longer than ids")
67+
except StopIteration as e:
68+
raise ValueError("texts iterable longer than ids") from e
6969

7070
links = _metadata.pop(METADATA_LINKS_KEY, set())
7171
if not isinstance(links, Set):
@@ -90,8 +90,8 @@ def _documents_to_nodes(
9090
try:
9191
_id = next(ids_it) if ids_it else None
9292
_id = _id or doc.metadata.pop(METADATA_CONTENT_ID_KEY, None)
93-
except StopIteration:
94-
raise ValueError("documents iterable longer than ids")
93+
except StopIteration as e:
94+
raise ValueError("documents iterable longer than ids") from e
9595
metadata = doc.metadata.copy()
9696
links = metadata.pop(METADATA_LINKS_KEY, set())
9797
if not isinstance(links, Set):

libs/langchain/ragstack_langchain/graph_store/extractors/html_link_extractor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,11 @@ def __init__(self, *, kind: str = "hyperlink", drop_fragments: bool = True):
6868
"""
6969
try:
7070
import bs4 # noqa:F401
71-
except ImportError:
71+
except ImportError as e:
7272
raise ImportError(
7373
"BeautifulSoup4 is required for HtmlLinkExtractor. "
7474
"Please install it with `pip install beautifulsoup4`."
75-
)
75+
) from e
7676

7777
self._kind = kind
7878
self.drop_fragments = drop_fragments

libs/llamaindex/ragstack_llamaindex/colbert/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
try:
22
from ragstack_colbert.base_retriever import BaseRetriever # noqa
3-
except (ImportError, ModuleNotFoundError):
3+
except (ImportError, ModuleNotFoundError) as e:
44
raise ImportError(
55
"Could not import ragstack-ai-colbert. "
66
"Please install it with `pip install ragstack-ai-llamaindex[colbert]`."
7-
)
7+
) from e
88

99
from .colbert_retriever import ColbertRetriever
1010

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ ignore = [
6363
]
6464

6565
select = [
66+
"B",
6667
"E",
6768
"F",
6869
"FLY",

scripts/format-example-notebooks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def main():
1111
}
1212

1313
nb_path = os.path.join("examples", "notebooks")
14-
for root, dirs, files in os.walk(nb_path):
14+
for root, _, files in os.walk(nb_path):
1515
for file in files:
1616
file = os.path.join(root, file)
1717
if ".ipynb_checkpoints" not in file and file.endswith(".ipynb"):

0 commit comments

Comments
 (0)