Skip to content

Commit 8b278a8

Browse files
committed
CrateDB: Format code. Satisfy linter and type checker. ruff + mypy
1 parent c561a95 commit 8b278a8

File tree

8 files changed

+14
-14
lines changed

8 files changed

+14
-14
lines changed

libs/community/langchain_community/chat_message_histories/cratedb.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
import typing as t
33

44
import sqlalchemy as sa
5-
from sqlalchemy_cratedb.support import refresh_after_dml, refresh_table
65
from langchain.schema import BaseMessage, _message_to_dict, messages_from_dict
6+
from sqlalchemy_cratedb.support import refresh_after_dml, refresh_table
77

88
from langchain_community.chat_message_histories.sql import (
99
BaseMessageConverter,

libs/community/langchain_community/vectorstores/cratedb/base.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
from langchain.utils import get_from_dict_or_env
2020
from langchain.vectorstores.pgvector import PGVector
2121
from sqlalchemy.orm import sessionmaker
22+
from sqlalchemy_cratedb.support import refresh_after_dml, refresh_table
2223

2324
from langchain_community.vectorstores.cratedb.model import ModelFactory
24-
from sqlalchemy_cratedb.support import refresh_after_dml, refresh_table
2525

2626

2727
class DistanceStrategy(str, enum.Enum):
@@ -87,7 +87,7 @@ def __post_init__(
8787
"""
8888

8989
self._engine = self._bind
90-
self.Session = sessionmaker(self._engine)
90+
self.Session = sessionmaker(bind=self._engine) # type: ignore[call-overload]
9191

9292
# Patch dialect to invoke `REFRESH TABLE` after each DML operation.
9393
refresh_after_dml(self._engine)
@@ -199,6 +199,7 @@ def drop_tables(self) -> None:
199199
def delete(
200200
self,
201201
ids: Optional[List[str]] = None,
202+
collection_only: bool = False,
202203
**kwargs: Any,
203204
) -> None:
204205
"""
@@ -214,7 +215,7 @@ def delete(
214215
patch, listening to `after_delete` events seems not be
215216
able to catch it.
216217
"""
217-
super().delete(ids=ids, **kwargs)
218+
super().delete(ids=ids, collection_only=collection_only, **kwargs)
218219

219220
# CrateDB: Synchronize data because `on_flush` does not catch it.
220221
with self.Session() as session:

libs/community/langchain_community/vectorstores/cratedb/extended.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
)
99

1010
import sqlalchemy
11-
1211
from langchain.schema.embeddings import Embeddings
1312

1413
from langchain_community.vectorstores.cratedb.base import (

libs/community/langchain_community/vectorstores/cratedb/model.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
from typing import Any, List, Optional, Tuple
33

44
import sqlalchemy
5-
from sqlalchemy_cratedb import ObjectType, FloatVector
65
from sqlalchemy.orm import Session, declarative_base, relationship
6+
from sqlalchemy_cratedb import FloatVector, ObjectType
77

88

99
def generate_uuid() -> str:
@@ -48,7 +48,7 @@ class CollectionStore(BaseModel):
4848
)
4949

5050
@classmethod
51-
def get_by_name(cls, session: Session, name: str) -> "CollectionStore":
51+
def get_by_name(cls, session: Session, name: str) -> Optional["CollectionStore"]:
5252
return session.query(cls).filter(cls.name == name).first() # type: ignore[attr-defined]
5353

5454
@classmethod
@@ -95,8 +95,8 @@ class EmbeddingStore(BaseModel):
9595
)
9696
collection = relationship("CollectionStore", back_populates="embeddings")
9797

98-
embedding = sqlalchemy.Column(FloatVector(self.dimensions))
99-
document = sqlalchemy.Column(sqlalchemy.String, nullable=True)
98+
embedding: sqlalchemy.Column = sqlalchemy.Column(FloatVector(self.dimensions))
99+
document: sqlalchemy.Column = sqlalchemy.Column(sqlalchemy.String, nullable=True)
100100
cmetadata: sqlalchemy.Column = sqlalchemy.Column(ObjectType, nullable=True)
101101

102102
# custom_id : any user defined id

libs/community/tests/integration_tests/document_loaders/test_sql_database.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,7 @@ def pytest_generate_tests(metafunc: "Metafunc") -> None:
122122
# use `docker compose up postgres` to start the instance
123123
# it will have the appropriate credentials set up including
124124
# being exposed on the appropriate port.
125-
urls.append(
126-
"crate://crate@localhost/?schema=testdrive"
127-
)
125+
urls.append("crate://crate@localhost/?schema=testdrive")
128126
ids.append("cratedb")
129127

130128
metafunc.parametrize("db_uri", urls, ids=ids)

libs/community/tests/integration_tests/vectorstores/test_cratedb.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
cd tests/integration_tests/vectorstores/docker-compose
55
docker-compose -f cratedb.yml up
66
"""
7+
78
import os
89
import re
910
from typing import Dict, Generator, List

libs/community/tests/unit_tests/test_sql_database.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import pytest
55
import sqlalchemy as sa
66
import sqlalchemy.orm
7-
from langchain_community.utilities.sql_database import SQLDatabase, truncate_word
87
from packaging import version
98
from sqlalchemy import (
109
Column,
@@ -18,6 +17,8 @@
1817
)
1918
from sqlalchemy.engine import Engine, Result
2019

20+
from langchain_community.utilities.sql_database import SQLDatabase, truncate_word
21+
2122
is_sqlalchemy_v1 = version.parse(sa.__version__).major == 1
2223

2324
metadata_obj = MetaData()

libs/langchain/langchain/memory/chat_message_histories/cratedb.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# handling optional imports.
1414
DEPRECATED_LOOKUP = {
1515
"CrateDBChatMessageHistory": "langchain_community.chat_message_histories",
16-
"CrateDBMessageConverter": "langchain_community.chat_message_histories"
16+
"CrateDBMessageConverter": "langchain_community.chat_message_histories",
1717
}
1818

1919
_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)

0 commit comments

Comments
 (0)