style(langchain): add ruff rule RUF012 (#34497)

Co-authored-by: Mason Daugherty <mason@langchain.dev>
Co-authored-by: Mason Daugherty <github@mdrxy.com>
This commit is contained in:
Christophe Bornet
2025-12-27 08:36:47 +01:00
committed by GitHub
parent 85f1ba2351
commit 0bd862b814
6 changed files with 7 additions and 8 deletions

View File

@@ -2,7 +2,7 @@
from __future__ import annotations
from collections.abc import Awaitable, Callable
from collections.abc import Awaitable, Callable, Sequence
from dataclasses import dataclass, field, replace
from inspect import iscoroutinefunction
from typing import (
@@ -338,7 +338,7 @@ class AgentMiddleware(Generic[StateT, ContextT]):
state_schema: type[StateT] = cast("type[StateT]", AgentState)
"""The schema for state passed to the middleware nodes."""
tools: list[BaseTool]
tools: Sequence[BaseTool]
"""Additional tools registered by the middleware."""
@property

View File

@@ -112,7 +112,6 @@ ignore = [
"FIX002", # Line contains TODO
"PERF203", # Rarely useful
"PLR09", # Too many something (arg, statements, etc)
"RUF012", # Doesn't play well with Pydantic
"TD002", # Missing author in TODO
"TD003", # Missing issue link in TODO

View File

@@ -293,7 +293,7 @@ def test_middleware_with_additional_tools() -> None:
return "middleware"
class ToolProvidingMiddleware(AgentMiddleware):
tools = [middleware_tool]
tools = (middleware_tool,)
# Model calls the middleware-provided tool
model = FakeToolCallingModel(

View File

@@ -31,7 +31,7 @@ class ProfileChatModel(BaseChatModel):
def _generate(self, messages, **kwargs): # type: ignore[no-untyped-def]
return ChatResult(generations=[ChatGeneration(message=AIMessage(content="Summary"))])
profile: ModelProfile | None = {"max_input_tokens": 1000}
profile: ModelProfile | None = ModelProfile(max_input_tokens=1000)
@property
def _llm_type(self) -> str:

View File

@@ -1,7 +1,7 @@
"""Unit tests for tool emulator middleware."""
import typing
from collections.abc import Callable
from collections.abc import Callable, Sequence
from itertools import cycle
from typing import Any, Literal
@@ -86,7 +86,7 @@ class FakeModel(GenericFakeChatModel):
class FakeEmulatorModel(BaseChatModel):
"""Fake model for emulating tool responses."""
responses: list[str] = ["Emulated response"]
responses: Sequence[str] = ("Emulated response",)
response_index: int = 0
def _generate(

View File

@@ -776,7 +776,7 @@ class TestDynamicModelWithResponseFormat:
# Custom model that we'll use to test whether the tool strategy is applied
# correctly at runtime.
class CustomModel(GenericFakeChatModel):
tool_bindings: list[Any] = []
tool_bindings: list[Any] = Field(default_factory=list)
def bind_tools(
self,