standard-tests: Add ruff rule UP (pyupgrade) (#31842)

See https://docs.astral.sh/ruff/rules/#pyupgrade-up
All auto-fixed
This commit is contained in:
Christophe Bornet
2025-07-03 16:12:31 +02:00
committed by GitHub
parent 802d2bf249
commit cd7dce687a
16 changed files with 63 additions and 71 deletions

View File

@@ -1,4 +1,5 @@
from typing import Any, Dict, Iterator, List, Optional
from collections.abc import Iterator
from typing import Any, Optional
from langchain_core.callbacks import (
CallbackManagerForLLMRun,
@@ -40,13 +41,13 @@ class ChatParrotLink(BaseChatModel):
temperature: Optional[float] = None
max_tokens: Optional[int] = None
timeout: Optional[int] = None
stop: Optional[List[str]] = None
stop: Optional[list[str]] = None
max_retries: int = 2
def _generate(
self,
messages: List[BaseMessage],
stop: Optional[List[str]] = None,
messages: list[BaseMessage],
stop: Optional[list[str]] = None,
run_manager: Optional[CallbackManagerForLLMRun] = None,
**kwargs: Any,
) -> ChatResult:
@@ -91,8 +92,8 @@ class ChatParrotLink(BaseChatModel):
def _stream(
self,
messages: List[BaseMessage],
stop: Optional[List[str]] = None,
messages: list[BaseMessage],
stop: Optional[list[str]] = None,
run_manager: Optional[CallbackManagerForLLMRun] = None,
**kwargs: Any,
) -> Iterator[ChatGenerationChunk]:
@@ -156,7 +157,7 @@ class ChatParrotLink(BaseChatModel):
return "echoing-chat-model-advanced"
@property
def _identifying_params(self) -> Dict[str, Any]:
def _identifying_params(self) -> dict[str, Any]:
"""Return a dictionary of identifying parameters.
This information is used by the LangChain callback system, which

View File

@@ -1,4 +1,4 @@
from typing import Any, Type
from typing import Any
from langchain_core.documents import Document
from langchain_core.retrievers import BaseRetriever
@@ -17,7 +17,7 @@ class ParrotRetriever(BaseRetriever):
class TestParrotRetrieverIntegration(RetrieversIntegrationTests):
@property
def retriever_constructor(self) -> Type[ParrotRetriever]:
def retriever_constructor(self) -> type[ParrotRetriever]:
return ParrotRetriever
@property

View File

@@ -1,4 +1,4 @@
from typing import Literal, Type
from typing import Literal
from langchain_core.tools import BaseTool
@@ -29,7 +29,7 @@ class ParrotMultiplyArtifactTool(BaseTool): # type: ignore
class TestParrotMultiplyToolUnit(ToolsUnitTests):
@property
def tool_constructor(self) -> Type[ParrotMultiplyTool]:
def tool_constructor(self) -> type[ParrotMultiplyTool]:
return ParrotMultiplyTool
@property
@@ -52,7 +52,7 @@ class TestParrotMultiplyToolUnit(ToolsUnitTests):
class TestParrotMultiplyToolIntegration(ToolsIntegrationTests):
@property
def tool_constructor(self) -> Type[ParrotMultiplyTool]:
def tool_constructor(self) -> type[ParrotMultiplyTool]:
return ParrotMultiplyTool
@property
@@ -75,7 +75,7 @@ class TestParrotMultiplyToolIntegration(ToolsIntegrationTests):
class TestParrotMultiplyArtifactToolIntegration(ToolsIntegrationTests):
@property
def tool_constructor(self) -> Type[ParrotMultiplyArtifactTool]:
def tool_constructor(self) -> type[ParrotMultiplyArtifactTool]:
return ParrotMultiplyArtifactTool
@property

View File

@@ -2,8 +2,6 @@
Test the standard tests on the custom chat model in the docs
"""
from typing import Type
from langchain_tests.integration_tests import ChatModelIntegrationTests
from langchain_tests.unit_tests import ChatModelUnitTests
@@ -12,7 +10,7 @@ from .custom_chat_model import ChatParrotLink
class TestChatParrotLinkUnit(ChatModelUnitTests):
@property
def chat_model_class(self) -> Type[ChatParrotLink]:
def chat_model_class(self) -> type[ChatParrotLink]:
return ChatParrotLink
@property
@@ -22,7 +20,7 @@ class TestChatParrotLinkUnit(ChatModelUnitTests):
class TestChatParrotLinkIntegration(ChatModelIntegrationTests):
@property
def chat_model_class(self) -> Type[ChatParrotLink]:
def chat_model_class(self) -> type[ChatParrotLink]:
return ChatParrotLink
@property

View File

@@ -1,5 +1,3 @@
from typing import Type
from langchain_core.embeddings import DeterministicFakeEmbedding, Embeddings
from langchain_tests.integration_tests import EmbeddingsIntegrationTests
@@ -8,7 +6,7 @@ from langchain_tests.unit_tests import EmbeddingsUnitTests
class TestFakeEmbeddingsUnit(EmbeddingsUnitTests):
@property
def embeddings_class(self) -> Type[Embeddings]:
def embeddings_class(self) -> type[Embeddings]:
return DeterministicFakeEmbedding
@property
@@ -18,7 +16,7 @@ class TestFakeEmbeddingsUnit(EmbeddingsUnitTests):
class TestFakeEmbeddingsIntegration(EmbeddingsIntegrationTests):
@property
def embeddings_class(self) -> Type[Embeddings]:
def embeddings_class(self) -> type[Embeddings]:
return DeterministicFakeEmbedding
@property

View File

@@ -1,7 +1,5 @@
"""Tests for the InMemoryStore class."""
from typing import Tuple
import pytest
from langchain_core.stores import InMemoryStore
@@ -13,7 +11,7 @@ from langchain_tests.integration_tests.base_store import (
class TestInMemoryStore(BaseStoreSyncTests):
@pytest.fixture
def three_values(self) -> Tuple[str, str, str]:
def three_values(self) -> tuple[str, str, str]:
return "foo", "bar", "buzz"
@pytest.fixture
@@ -23,7 +21,7 @@ class TestInMemoryStore(BaseStoreSyncTests):
class TestInMemoryStoreAsync(BaseStoreAsyncTests):
@pytest.fixture
def three_values(self) -> Tuple[str, str, str]: # type: ignore
def three_values(self) -> tuple[str, str, str]: # type: ignore
return "foo", "bar", "buzz"
@pytest.fixture