From 1276bf3e1d801ac9490eb9553349c57e3e9e9d0d Mon Sep 17 00:00:00 2001 From: Christophe Bornet Date: Mon, 7 Jul 2025 16:07:39 +0200 Subject: [PATCH] standard-tests: Add ruff rules PGH (#31869) See https://docs.astral.sh/ruff/rules/#pygrep-hooks-pgh --- .../langchain_tests/integration_tests/base_store.py | 2 +- .../langchain_tests/integration_tests/chat_models.py | 6 +++--- .../langchain_tests/integration_tests/indexer.py | 8 ++++---- .../langchain_tests/unit_tests/chat_models.py | 12 ++++++------ libs/standard-tests/pyproject.toml | 2 +- .../tests/unit_tests/test_basic_tool.py | 4 ++-- .../tests/unit_tests/test_in_memory_base_store.py | 6 +++--- 7 files changed, 20 insertions(+), 20 deletions(-) diff --git a/libs/standard-tests/langchain_tests/integration_tests/base_store.py b/libs/standard-tests/langchain_tests/integration_tests/base_store.py index 446e4eb3929..0b04104de34 100644 --- a/libs/standard-tests/langchain_tests/integration_tests/base_store.py +++ b/libs/standard-tests/langchain_tests/integration_tests/base_store.py @@ -149,7 +149,7 @@ class BaseStoreSyncTests(BaseStandardTests, Generic[V]): assert sorted(kv_store.yield_keys(prefix="foo")) == ["foo"] -class BaseStoreAsyncTests(BaseStandardTests): +class BaseStoreAsyncTests(BaseStandardTests, Generic[V]): """Test suite for checking the key-value API of a BaseStore. This test suite verifies the basic key-value API of a BaseStore. diff --git a/libs/standard-tests/langchain_tests/integration_tests/chat_models.py b/libs/standard-tests/langchain_tests/integration_tests/chat_models.py index be1703a77b4..b9f58010f60 100644 --- a/libs/standard-tests/langchain_tests/integration_tests/chat_models.py +++ b/libs/standard-tests/langchain_tests/integration_tests/chat_models.py @@ -1346,7 +1346,7 @@ class ChatModelIntegrationTests(ChatModelTests): # Test stream full: Optional[BaseMessageChunk] = None for chunk in model_with_tools.stream(query): - full = chunk if full is None else full + chunk # type: ignore + full = chunk if full is None else full + chunk # type: ignore[assignment] assert isinstance(full, AIMessage) _validate_tool_call_message(full) @@ -1407,7 +1407,7 @@ class ChatModelIntegrationTests(ChatModelTests): # Test astream full: Optional[BaseMessageChunk] = None async for chunk in model_with_tools.astream(query): - full = chunk if full is None else full + chunk # type: ignore + full = chunk if full is None else full + chunk # type: ignore[assignment] assert isinstance(full, AIMessage) _validate_tool_call_message(full) @@ -1743,7 +1743,7 @@ class ChatModelIntegrationTests(ChatModelTests): full: Optional[BaseMessageChunk] = None for chunk in model_with_tools.stream(query): - full = chunk if full is None else full + chunk # type: ignore + full = chunk if full is None else full + chunk # type: ignore[assignment] assert isinstance(full, AIMessage) _validate_tool_call_message_no_args(full) diff --git a/libs/standard-tests/langchain_tests/integration_tests/indexer.py b/libs/standard-tests/langchain_tests/integration_tests/indexer.py index 4f549c49475..9d95ac9ee11 100644 --- a/libs/standard-tests/langchain_tests/integration_tests/indexer.py +++ b/libs/standard-tests/langchain_tests/integration_tests/indexer.py @@ -49,7 +49,7 @@ class DocumentIndexerTestSuite(ABC): # Ordering is not guaranteed, need to test carefully documents = index.get(ids) - sorted_documents = sorted(documents, key=lambda x: x.id) # type: ignore + sorted_documents = sorted(documents, key=lambda x: x.id or "") if sorted_documents[0].page_content == "bar": assert sorted_documents[0] == Document( @@ -196,7 +196,7 @@ class DocumentIndexerTestSuite(ABC): } retrieved_documents = index.get(["1", "2", "3", "4"]) # The ordering is not guaranteed, so we use a set. - assert sorted(retrieved_documents, key=lambda x: x.id) == [ # type: ignore + assert sorted(retrieved_documents, key=lambda x: x.id or "") == [ Document(page_content="foo", metadata={"id": 1}, id="1"), Document(page_content="bar", metadata={"id": 2}, id="2"), ] @@ -239,7 +239,7 @@ class AsyncDocumentIndexTestSuite(ABC): # Ordering is not guaranteed, need to test carefully documents = await index.aget(ids) - sorted_documents = sorted(documents, key=lambda x: x.id) # type: ignore + sorted_documents = sorted(documents, key=lambda x: x.id or "") if sorted_documents[0].page_content == "bar": assert sorted_documents[0] == Document( @@ -388,7 +388,7 @@ class AsyncDocumentIndexTestSuite(ABC): } retrieved_documents = await index.aget(["1", "2", "3", "4"]) # The ordering is not guaranteed, so we use a set. - assert sorted(retrieved_documents, key=lambda x: x.id) == [ # type: ignore + assert sorted(retrieved_documents, key=lambda x: x.id or "") == [ Document(page_content="foo", metadata={"id": 1}, id="1"), Document(page_content="bar", metadata={"id": 2}, id="2"), ] diff --git a/libs/standard-tests/langchain_tests/unit_tests/chat_models.py b/libs/standard-tests/langchain_tests/unit_tests/chat_models.py index 5ba78941e57..24b2cfc2710 100644 --- a/libs/standard-tests/langchain_tests/unit_tests/chat_models.py +++ b/libs/standard-tests/langchain_tests/unit_tests/chat_models.py @@ -908,7 +908,7 @@ class ChatModelUnitTests(ChatModelTests): # Doing a mypy ignore here since some of the tools are from pydantic # BaseModel 2 which isn't typed properly yet. This will need to be fixed # so type checking does not become annoying to users. - tool_model = model.bind_tools(tools, tool_choice="any") # type: ignore + tool_model = model.bind_tools(tools, tool_choice="any") # type: ignore[arg-type] assert isinstance(tool_model, RunnableBinding) @pytest.mark.parametrize("schema", TEST_PYDANTIC_MODELS) @@ -962,19 +962,19 @@ class ChatModelUnitTests(ChatModelTests): ls_params = model._get_ls_params() try: - ExpectedParams(**ls_params) # type: ignore + ExpectedParams(**ls_params) # type: ignore[arg-type] except ValidationErrorV1 as e: pytest.fail(f"Validation error: {e}") # Test optional params model = self.chat_model_class( - max_tokens=10, - stop=["test"], - **self.chat_model_params, # type: ignore + max_tokens=10, # type: ignore[call-arg] + stop=["test"], # type: ignore[call-arg] + **self.chat_model_params, ) ls_params = model._get_ls_params() try: - ExpectedParams(**ls_params) # type: ignore + ExpectedParams(**ls_params) # type: ignore[arg-type] except ValidationErrorV1 as e: pytest.fail(f"Validation error: {e}") diff --git a/libs/standard-tests/pyproject.toml b/libs/standard-tests/pyproject.toml index 566c7a57207..828d4842570 100644 --- a/libs/standard-tests/pyproject.toml +++ b/libs/standard-tests/pyproject.toml @@ -55,7 +55,7 @@ ignore_missing_imports = true target-version = "py39" [tool.ruff.lint] -select = ["E", "F", "I", "T201", "UP",] +select = ["E", "F", "I", "PGH", "T201", "UP",] pyupgrade.keep-runtime-typing = true [tool.coverage.run] diff --git a/libs/standard-tests/tests/unit_tests/test_basic_tool.py b/libs/standard-tests/tests/unit_tests/test_basic_tool.py index 2922faad5c2..8af2750a9d1 100644 --- a/libs/standard-tests/tests/unit_tests/test_basic_tool.py +++ b/libs/standard-tests/tests/unit_tests/test_basic_tool.py @@ -6,7 +6,7 @@ from langchain_tests.integration_tests import ToolsIntegrationTests from langchain_tests.unit_tests import ToolsUnitTests -class ParrotMultiplyTool(BaseTool): # type: ignore +class ParrotMultiplyTool(BaseTool): name: str = "ParrotMultiplyTool" description: str = ( "Multiply two numbers like a parrot. Parrots always add eighty for their matey." @@ -16,7 +16,7 @@ class ParrotMultiplyTool(BaseTool): # type: ignore return a * b + 80 -class ParrotMultiplyArtifactTool(BaseTool): # type: ignore +class ParrotMultiplyArtifactTool(BaseTool): name: str = "ParrotMultiplyArtifactTool" description: str = ( "Multiply two numbers like a parrot. Parrots always add eighty for their matey." diff --git a/libs/standard-tests/tests/unit_tests/test_in_memory_base_store.py b/libs/standard-tests/tests/unit_tests/test_in_memory_base_store.py index d8d635cf420..7349d3ffc5e 100644 --- a/libs/standard-tests/tests/unit_tests/test_in_memory_base_store.py +++ b/libs/standard-tests/tests/unit_tests/test_in_memory_base_store.py @@ -9,7 +9,7 @@ from langchain_tests.integration_tests.base_store import ( ) -class TestInMemoryStore(BaseStoreSyncTests): +class TestInMemoryStore(BaseStoreSyncTests[str]): @pytest.fixture def three_values(self) -> tuple[str, str, str]: return "foo", "bar", "buzz" @@ -19,9 +19,9 @@ class TestInMemoryStore(BaseStoreSyncTests): return InMemoryStore() -class TestInMemoryStoreAsync(BaseStoreAsyncTests): +class TestInMemoryStoreAsync(BaseStoreAsyncTests[str]): @pytest.fixture - def three_values(self) -> tuple[str, str, str]: # type: ignore + def three_values(self) -> tuple[str, str, str]: return "foo", "bar", "buzz" @pytest.fixture