Skip to content

Commit beecea7

Browse files
author
wangziren
committed
fix: align AgentSideConnection.to_agent type with AgentFactory
AgentSideConnection declares its factory parameter as Callable[[Client], Agent] | Agent, but _prepare always invokes it with the AgentSideConnection itself (to_agent(self)). The narrower AgentFactory = Callable[[AgentSideConnection], Agent] used by AcpServer is therefore not assignable to it under parameter contravariance, so a strict type-checker consumer passing an AgentFactory into AgentSideConnection gets a spurious type error (and has to cast). Narrow the four to_agent declarations to Callable[[AgentSideConnection], Agent] | Agent so they match AgentFactory, and drop the now-unused Client import.
1 parent 9d07d78 commit beecea7

2 files changed

Lines changed: 5 additions & 5 deletions

File tree

‎src/acp/agent/connection.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from .._transport import Transport
1010
from ..connection import Connection, MethodHandler
11-
from ..interfaces import Agent, Client
11+
from ..interfaces import Agent
1212
from ..meta import CLIENT_METHODS
1313
from ..schema import (
1414
AcceptElicitationResponse,
@@ -95,7 +95,7 @@ class AgentSideConnection:
9595

9696
def __init__(
9797
self,
98-
to_agent: Callable[[Client], Agent] | Agent,
98+
to_agent: Callable[[AgentSideConnection], Agent] | Agent,
9999
input_stream: Any,
100100
output_stream: Any = None,
101101
listening: bool = True,
@@ -119,7 +119,7 @@ def __init__(
119119
@classmethod
120120
def attach(
121121
cls,
122-
to_agent: Callable[[Client], Agent] | Agent,
122+
to_agent: Callable[[AgentSideConnection], Agent] | Agent,
123123
connection: Connection,
124124
*,
125125
use_unstable_protocol: bool = False,
@@ -133,7 +133,7 @@ def attach(
133133

134134
def _prepare(
135135
self,
136-
to_agent: Callable[[Client], Agent] | Agent,
136+
to_agent: Callable[[AgentSideConnection], Agent] | Agent,
137137
*,
138138
use_unstable_protocol: bool,
139139
) -> tuple[Agent, MethodHandler]:

‎src/acp/stdio.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ async def spawn_agent_process(
185185

186186
@asynccontextmanager
187187
async def spawn_client_process(
188-
to_agent: Callable[[Client], Agent] | Agent,
188+
to_agent: Callable[[AgentSideConnection], Agent] | Agent,
189189
command: str,
190190
*args: str,
191191
env: Mapping[str, str] | None = None,

0 commit comments

Comments
 (0)