fix: align AgentSideConnection.to_agent type with AgentFactory - #157
Open
extreme-structure wants to merge 1 commit into
Open
extreme-structure wants to merge 1 commit into
extreme-structure wants to merge 1 commit into
Conversation
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.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
AgentSideConnectiondeclares its factory parameter asCallable[[Client], Agent] | Agent, but_preparealways invokes it with theAgentSideConnectionitself (to_agent(self)). The narrowerAgentFactory = Callable[[AgentSideConnection], Agent]used byAcpServeris therefore not assignable to it under parameter contravariance.Result: a strict type-checker consumer (mypy
--strict/ty) that passes anAgentFactoryintoAgentSideConnectiongets a spurious error at the call site — e.g.AcpServer._handle_initialize'sAgentSideConnection(self.agent_factory, transport)— and has to insert acast.Fix
Narrow the four
to_agentdeclarations toCallable[[AgentSideConnection], Agent] | Agentso they matchAgentFactory:AgentSideConnection.__init__AgentSideConnection.attachAgentSideConnection._preparespawn_client_processAlso drop the now-unused
Clientimport fromagent/connection.py.Notes
ClientSideConnection.__init__/spawn_agent_process) usesto_client: Callable[[Agent], Client] | Clientwhere the factory is actually invoked with theClientSideConnectionitself — a similar but currently self-consistent imprecision, left out of scope here.ty checkin my environment (dependency fetch timed out); the change is annotation-only andpy_compilepasses.