Skip to content

Commit

Permalink
Improve lint setup (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
cbornet authored Sep 27, 2024
1 parent 2490467 commit 460bf30
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 23 deletions.
5 changes: 1 addition & 4 deletions libs/astradb/langchain_astradb/__init__.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
"""Astra DB integration for LangChain."""

# ruff: noqa: I001

from astrapy.info import CollectionVectorServiceOptions

from langchain_astradb.cache import AstraDBCache, AstraDBSemanticCache
from langchain_astradb.chat_message_histories import AstraDBChatMessageHistory
from langchain_astradb.document_loaders import AstraDBLoader
from langchain_astradb.graph_vectorstores import AstraDBGraphVectorStore
from langchain_astradb.storage import AstraDBByteStore, AstraDBStore
from langchain_astradb.vectorstores import AstraDBVectorStore

from langchain_astradb.graph_vectorstores import AstraDBGraphVectorStore

__all__ = [
"AstraDBByteStore",
"AstraDBStore",
Expand Down
5 changes: 1 addition & 4 deletions libs/astradb/langchain_astradb/graph_vectorstores.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
"""Astra DB graph vector store integration."""

# Leave TODO's alone
# ruff: noqa: FIX002 TD002 TD003

from __future__ import annotations

import secrets
Expand All @@ -21,8 +18,8 @@
from langchain_core.documents import Document
from typing_extensions import override

from langchain_astradb import AstraDBVectorStore
from langchain_astradb.utils.mmr_traversal import MmrHelper
from langchain_astradb.vectorstores import AstraDBVectorStore

if TYPE_CHECKING:
from langchain_core.embeddings import Embeddings
Expand Down
5 changes: 2 additions & 3 deletions libs/astradb/langchain_astradb/utils/mmr_traversal.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"""Tools for the Graph Traversal Maximal Marginal Relevance (MMR) reranking."""

# ruff: noqa: EM101 TRY003

from __future__ import annotations

import dataclasses
Expand Down Expand Up @@ -141,10 +139,11 @@ def _pop_candidate(self, candidate_id: str) -> NDArray[np.float32]:
# Get the embedding for the id.
index = self.candidate_id_to_index.pop(candidate_id)
if self.candidates[index].id != candidate_id:
raise ValueError(
msg = (
"ID in self.candidate_id_to_index doesn't match the ID of the "
"corresponding index in self.candidates"
)
raise ValueError(msg)
embedding: NDArray[np.float32] = self.candidate_embeddings[index].copy()

# Swap that index with the last index in the candidates and
Expand Down
10 changes: 2 additions & 8 deletions libs/astradb/langchain_astradb/vectorstores.py
Original file line number Diff line number Diff line change
Expand Up @@ -983,10 +983,7 @@ def add_texts(
inserted_ids = insert_many_result.inserted_ids
except InsertManyException as err:
# check that the error is solely due to already-existing documents
error_codes = {
getattr(err_desc, "error_code", None)
for err_desc in err.error_descriptors
}
error_codes = {err_desc.error_code for err_desc in err.error_descriptors}
if error_codes == {DOCUMENT_ALREADY_EXISTS_API_ERROR_CODE}:
inserted_ids = err.partial_result.inserted_ids
inserted_ids_set = set(inserted_ids)
Expand Down Expand Up @@ -1115,10 +1112,7 @@ async def aadd_texts(
inserted_ids = insert_many_result.inserted_ids
except InsertManyException as err:
# check that the error is solely due to already-existing documents
error_codes = {
getattr(err_desc, "error_code", None)
for err_desc in err.error_descriptors
}
error_codes = {err_desc.error_code for err_desc in err.error_descriptors}
if error_codes == {DOCUMENT_ALREADY_EXISTS_API_ERROR_CODE}:
inserted_ids = err.partial_result.inserted_ids
inserted_ids_set = set(inserted_ids)
Expand Down
7 changes: 5 additions & 2 deletions libs/astradb/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,13 @@ flake8-annotations.mypy-init-return = true
select = ["ALL"]
ignore = [
"COM812", # Messes with the formatter
"ERA", # Do we want to activate (no commented code) ?
"D101", # We prefer using the __init__ docstring to document the class
"ERA001", # Do we want to activate (no commented code) ?
"FIX002", # Accept TODOs
"ISC001", # Messes with the formatter
"PLR09", # TODO: do we enforce these ones (complexity) ?
"D101", # We prefer using the __init__ docstring to document the class
"TD002", # We have TODOs authors by git
"TD003",
]

[tool.ruff.lint.per-file-ignores]
Expand Down
2 changes: 0 additions & 2 deletions libs/astradb/tests/integration_tests/test_graphvectorstore.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
Refer to `test_vectorstores.py` for the requirements to run.
"""

# ruff: noqa: FIX002 TD002 TD003

from __future__ import annotations

from typing import TYPE_CHECKING
Expand Down

0 comments on commit 460bf30

Please sign in to comment.