Skip to content

Commit 493ad31

Browse files
committed
fix(contrib): fix pyright/basedpyright errors in google_adk_agents MCP tests
The fake toolset factories in test_mcp.py and test_stateful_mcp.py were annotated as returning _FakeToolset, which pyright/basedpyright correctly flagged as incompatible with TemporalMcpToolSetProvider's/ TemporalStatefulMcpToolSetProvider's toolset_factory parameter type of Callable[[Any | None], McpToolset], since _FakeToolset is a structurally similar stand-in but not a subclass of McpToolset. Annotate the factories as returning McpToolset and cast the fake instance through object first (as basedpyright's reportInvalidCast requires for unrelated concrete types), matching CI's build-lint-test/test-latest-deps failure on PR #1664.
1 parent e16eefa commit 493ad31

2 files changed

Lines changed: 19 additions & 16 deletions

File tree

tests/contrib/google_adk_agents/test_mcp.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@
2222
honors that call's ``factory_argument``, and always closes the toolset.
2323
"""
2424

25-
from typing import Any
25+
from typing import Any, cast
2626

2727
import pytest
2828
from google.adk.events import EventActions
29+
from google.adk.tools.mcp_tool import McpToolset
2930

3031
from temporalio.contrib.google_adk_agents._mcp import (
3132
TemporalMcpToolSetProvider,
@@ -103,10 +104,10 @@ async def test_call_tool_creates_and_closes_fresh_toolset_each_call():
103104
"""Each call_tool builds its own toolset and closes it, every time."""
104105
created: list[_FakeToolset] = []
105106

106-
def factory(arg: Any) -> _FakeToolset:
107+
def factory(arg: Any) -> McpToolset:
107108
toolset = _FakeToolset(arg)
108109
created.append(toolset)
109-
return toolset
110+
return cast(McpToolset, cast(object, toolset))
110111

111112
provider = TemporalMcpToolSetProvider("stateless_reuse", factory)
112113
_, call_tool = provider._get_activities()
@@ -123,10 +124,10 @@ def factory(arg: Any) -> _FakeToolset:
123124
async def test_get_tools_creates_and_closes_fresh_toolset():
124125
created: list[_FakeToolset] = []
125126

126-
def factory(arg: Any) -> _FakeToolset:
127+
def factory(arg: Any) -> McpToolset:
127128
toolset = _FakeToolset(arg)
128129
created.append(toolset)
129-
return toolset
130+
return cast(McpToolset, cast(object, toolset))
130131

131132
provider = TemporalMcpToolSetProvider("stateless_list", factory)
132133
get_tools, _ = provider._get_activities()
@@ -145,10 +146,10 @@ async def test_factory_argument_honored_on_every_call():
145146
"""
146147
created: list[_FakeToolset] = []
147148

148-
def factory(arg: Any) -> _FakeToolset:
149+
def factory(arg: Any) -> McpToolset:
149150
toolset = _FakeToolset(arg)
150151
created.append(toolset)
151-
return toolset
152+
return cast(McpToolset, cast(object, toolset))
152153

153154
provider = TemporalMcpToolSetProvider("stateless_routing", factory)
154155
_, call_tool = provider._get_activities()
@@ -164,10 +165,10 @@ async def test_call_tool_closes_toolset_on_error():
164165
"""A failure mid-call still closes the toolset (no leak on the error path)."""
165166
created: list[_FakeToolset] = []
166167

167-
def factory(arg: Any) -> _FakeToolset:
168+
def factory(arg: Any) -> McpToolset:
168169
toolset = _FakeToolset(arg, fail_run=True)
169170
created.append(toolset)
170-
return toolset
171+
return cast(McpToolset, cast(object, toolset))
171172

172173
provider = TemporalMcpToolSetProvider("stateless_run_error", factory)
173174
_, call_tool = provider._get_activities()
@@ -182,10 +183,10 @@ def factory(arg: Any) -> _FakeToolset:
182183
async def test_get_tools_closes_toolset_on_error():
183184
created: list[_FakeToolset] = []
184185

185-
def factory(arg: Any) -> _FakeToolset:
186+
def factory(arg: Any) -> McpToolset:
186187
toolset = _FakeToolset(arg, fail_get_tools=True)
187188
created.append(toolset)
188-
return toolset
189+
return cast(McpToolset, cast(object, toolset))
189190

190191
provider = TemporalMcpToolSetProvider("stateless_list_error", factory)
191192
get_tools, _ = provider._get_activities()
@@ -201,10 +202,10 @@ async def test_call_tool_no_matching_tool_still_closes():
201202
"""A business-logic ApplicationError still closes the fresh toolset."""
202203
created: list[_FakeToolset] = []
203204

204-
def factory(arg: Any) -> _FakeToolset:
205+
def factory(arg: Any) -> McpToolset:
205206
toolset = _FakeToolset(arg)
206207
created.append(toolset)
207-
return toolset
208+
return cast(McpToolset, cast(object, toolset))
208209

209210
provider = TemporalMcpToolSetProvider("stateless_no_match", factory)
210211
_, call_tool = provider._get_activities()

tests/contrib/google_adk_agents/test_stateful_mcp.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525

2626
import uuid
2727
from datetime import timedelta
28-
from typing import Any
28+
from typing import Any, cast
29+
30+
from google.adk.tools.mcp_tool import McpToolset
2931

3032
from temporalio import workflow
3133
from temporalio.client import Client
@@ -73,10 +75,10 @@ async def close(self) -> None:
7375
self.closed = True
7476

7577

76-
def _factory(arg: Any) -> _FakeToolset:
78+
def _factory(arg: Any) -> McpToolset:
7779
toolset = _FakeToolset(arg)
7880
CREATED.append(toolset)
79-
return toolset # type: ignore[return-value]
81+
return cast(McpToolset, cast(object, toolset))
8082

8183

8284
@workflow.defn

0 commit comments

Comments
 (0)