Skip to content

Commit b8fff0f

Browse files
committed
update typing
1 parent b832950 commit b8fff0f

File tree

6 files changed

+25
-6
lines changed

6 files changed

+25
-6
lines changed

libs/langchain-mongodb/langchain_mongodb/retrievers/hybrid_search.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,12 @@ def _get_relevant_documents(
8686
# Get the appropriate value for k.
8787
is_top_k_set = False
8888
with warnings.catch_warnings():
89-
# Ignore warnings raised by base class.
89+
# Ignore warning raised by checking the value of top_k.
9090
warnings.simplefilter("ignore", DeprecationWarning)
9191
if self.top_k is not None:
9292
is_top_k_set = True
9393
default_k = self.k if not is_top_k_set else self.top_k
94-
k = kwargs.get("k", default_k)
94+
k: int = kwargs.get("k", default_k) # type:ignore[assignment]
9595

9696
# First we build up the aggregation pipeline,
9797
# then it is passed to the server to execute

libs/langchain-mongodb/tests/integration_tests/test_cache.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def test_mongodb_cache(
157157
_execute_test(prompt, llm, response)
158158
finally:
159159
get_llm_cache().clear()
160-
get_llm_cache().close()
160+
get_llm_cache().close() # type:ignore[attr-defined]
161161

162162

163163
@pytest.mark.parametrize(
@@ -209,4 +209,4 @@ def test_mongodb_atlas_cache_matrix(
209209
generations=llm_generations, llm_output={}
210210
)
211211
get_llm_cache().clear()
212-
get_llm_cache().close()
212+
get_llm_cache().close() # type:ignore[attr-defined]

libs/langchain-mongodb/tests/integration_tests/test_chat_message_histories.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,4 @@ def test_memory_with_message_store() -> None:
4242
memory.chat_memory.clear()
4343

4444
assert memory.chat_memory.messages == []
45-
memory.chat_memory.close()
45+
memory.chat_memory.close() # type:ignore[attr-defined]

libs/langchain-mongodb/tests/integration_tests/test_retrievers_standard.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ def setup_test() -> tuple[Collection, MongoDBAtlasVectorSearch]:
6868

6969

7070
class TestMongoDBAtlasFullTextSearchRetriever(RetrieversIntegrationTests):
71+
_coll: Collection
72+
7173
@classmethod
7274
def setup_class(cls):
7375
cls._coll, _ = setup_test()
@@ -98,6 +100,9 @@ def retriever_query_example(self) -> str:
98100

99101

100102
class TestMongoDBAtlasHybridSearchRetriever(RetrieversIntegrationTests):
103+
_coll: Collection
104+
_vs: MongoDBAtlasVectorSearch
105+
101106
@classmethod
102107
def setup_class(cls):
103108
cls._coll, cls._vs = setup_test()

libs/langchain-mongodb/tests/integration_tests/test_tools.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
11
from typing import Type
22

3+
import pytest
34
from langchain_tests.integration_tests import ToolsIntegrationTests
45

56
from langchain_mongodb.agent_toolkit.tool import (
67
InfoMongoDBDatabaseTool,
78
ListMongoDBDatabaseTool,
9+
MongoDBDatabase,
810
QueryMongoDBCheckerTool,
911
QueryMongoDBDatabaseTool,
1012
)
1113
from tests.utils import create_database, create_llm
1214

15+
# Ignore ResourceWarning raised by base class.
16+
pytestmark = pytest.mark.filterwarnings("ignore:unclosed:ResourceWarning")
17+
1318

1419
class TestQueryMongoDBDatabaseToolIntegration(ToolsIntegrationTests):
20+
_db: MongoDBDatabase
21+
1522
@classmethod
1623
def setup_class(cls):
1724
cls._db = create_database()
@@ -34,6 +41,8 @@ def tool_invoke_params_example(self) -> dict:
3441

3542

3643
class TestInfoMongoDBDatabaseToolIntegration(ToolsIntegrationTests):
44+
_db: MongoDBDatabase
45+
3746
@classmethod
3847
def setup_class(cls):
3948
cls._db = create_database()
@@ -56,6 +65,8 @@ def tool_invoke_params_example(self) -> dict:
5665

5766

5867
class TestListMongoDBDatabaseToolIntegration(ToolsIntegrationTests):
68+
_db: MongoDBDatabase
69+
5970
@classmethod
6071
def setup_class(cls):
6172
cls._db = create_database()
@@ -78,6 +89,8 @@ def tool_invoke_params_example(self) -> dict:
7889

7990

8091
class TestQueryMongoDBCheckerToolIntegration(ToolsIntegrationTests):
92+
_db: MongoDBDatabase
93+
8194
@classmethod
8295
def setup_class(cls):
8396
cls._db = create_database()

libs/langchain-mongodb/tests/unit_tests/test_index.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from time import sleep
2+
from typing import Generator
23

34
import pytest
45
from pymongo import MongoClient
@@ -12,7 +13,7 @@
1213

1314

1415
@pytest.fixture
15-
def collection() -> Collection:
16+
def collection() -> Generator[Collection]:
1617
"""Collection on MongoDB Cluster, not an Atlas one."""
1718
client: MongoClient = MongoClient()
1819
yield client["db"]["collection"]

0 commit comments

Comments
 (0)