mirror of
https://github.com/hwchase17/langchain.git
synced 2026-06-09 18:50:33 +00:00
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:
committed by
GitHub
parent
85f1ba2351
commit
0bd862b814
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from collections.abc import Awaitable, Callable
|
from collections.abc import Awaitable, Callable, Sequence
|
||||||
from dataclasses import dataclass, field, replace
|
from dataclasses import dataclass, field, replace
|
||||||
from inspect import iscoroutinefunction
|
from inspect import iscoroutinefunction
|
||||||
from typing import (
|
from typing import (
|
||||||
@@ -338,7 +338,7 @@ class AgentMiddleware(Generic[StateT, ContextT]):
|
|||||||
state_schema: type[StateT] = cast("type[StateT]", AgentState)
|
state_schema: type[StateT] = cast("type[StateT]", AgentState)
|
||||||
"""The schema for state passed to the middleware nodes."""
|
"""The schema for state passed to the middleware nodes."""
|
||||||
|
|
||||||
tools: list[BaseTool]
|
tools: Sequence[BaseTool]
|
||||||
"""Additional tools registered by the middleware."""
|
"""Additional tools registered by the middleware."""
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|||||||
@@ -112,7 +112,6 @@ ignore = [
|
|||||||
"FIX002", # Line contains TODO
|
"FIX002", # Line contains TODO
|
||||||
"PERF203", # Rarely useful
|
"PERF203", # Rarely useful
|
||||||
"PLR09", # Too many something (arg, statements, etc)
|
"PLR09", # Too many something (arg, statements, etc)
|
||||||
"RUF012", # Doesn't play well with Pydantic
|
|
||||||
"TD002", # Missing author in TODO
|
"TD002", # Missing author in TODO
|
||||||
"TD003", # Missing issue link in TODO
|
"TD003", # Missing issue link in TODO
|
||||||
|
|
||||||
|
|||||||
@@ -293,7 +293,7 @@ def test_middleware_with_additional_tools() -> None:
|
|||||||
return "middleware"
|
return "middleware"
|
||||||
|
|
||||||
class ToolProvidingMiddleware(AgentMiddleware):
|
class ToolProvidingMiddleware(AgentMiddleware):
|
||||||
tools = [middleware_tool]
|
tools = (middleware_tool,)
|
||||||
|
|
||||||
# Model calls the middleware-provided tool
|
# Model calls the middleware-provided tool
|
||||||
model = FakeToolCallingModel(
|
model = FakeToolCallingModel(
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ class ProfileChatModel(BaseChatModel):
|
|||||||
def _generate(self, messages, **kwargs): # type: ignore[no-untyped-def]
|
def _generate(self, messages, **kwargs): # type: ignore[no-untyped-def]
|
||||||
return ChatResult(generations=[ChatGeneration(message=AIMessage(content="Summary"))])
|
return ChatResult(generations=[ChatGeneration(message=AIMessage(content="Summary"))])
|
||||||
|
|
||||||
profile: ModelProfile | None = {"max_input_tokens": 1000}
|
profile: ModelProfile | None = ModelProfile(max_input_tokens=1000)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def _llm_type(self) -> str:
|
def _llm_type(self) -> str:
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
"""Unit tests for tool emulator middleware."""
|
"""Unit tests for tool emulator middleware."""
|
||||||
|
|
||||||
import typing
|
import typing
|
||||||
from collections.abc import Callable
|
from collections.abc import Callable, Sequence
|
||||||
from itertools import cycle
|
from itertools import cycle
|
||||||
from typing import Any, Literal
|
from typing import Any, Literal
|
||||||
|
|
||||||
@@ -86,7 +86,7 @@ class FakeModel(GenericFakeChatModel):
|
|||||||
class FakeEmulatorModel(BaseChatModel):
|
class FakeEmulatorModel(BaseChatModel):
|
||||||
"""Fake model for emulating tool responses."""
|
"""Fake model for emulating tool responses."""
|
||||||
|
|
||||||
responses: list[str] = ["Emulated response"]
|
responses: Sequence[str] = ("Emulated response",)
|
||||||
response_index: int = 0
|
response_index: int = 0
|
||||||
|
|
||||||
def _generate(
|
def _generate(
|
||||||
|
|||||||
@@ -776,7 +776,7 @@ class TestDynamicModelWithResponseFormat:
|
|||||||
# Custom model that we'll use to test whether the tool strategy is applied
|
# Custom model that we'll use to test whether the tool strategy is applied
|
||||||
# correctly at runtime.
|
# correctly at runtime.
|
||||||
class CustomModel(GenericFakeChatModel):
|
class CustomModel(GenericFakeChatModel):
|
||||||
tool_bindings: list[Any] = []
|
tool_bindings: list[Any] = Field(default_factory=list)
|
||||||
|
|
||||||
def bind_tools(
|
def bind_tools(
|
||||||
self,
|
self,
|
||||||
|
|||||||
Reference in New Issue
Block a user