Skip to content

Commit 51dc7a5

Browse files
committed
Fix basedpyright warnings (deprecated Optional/Mapping aliases, unused bindings)
basedpyright fails CI on warnings: replace typing.Optional/typing.Mapping with PEP 604/collections.abc forms, drop two unused query-result bindings, and mark the intentionally-unused node_input parameters (the name is load-bearing for ADK FunctionNode binding) with targeted ignores.
1 parent 82dad30 commit 51dc7a5

5 files changed

Lines changed: 29 additions & 28 deletions

File tree

temporalio/contrib/google_adk_agents/_hitl.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515

1616
from __future__ import annotations
1717

18+
from collections.abc import Mapping
1819
from dataclasses import dataclass
19-
from typing import Any, Literal, Mapping, Optional
20+
from typing import Any, Literal
2021

2122
from google.adk.events import Event
2223
from google.adk.tools.tool_confirmation import ToolConfirmation
@@ -64,12 +65,12 @@ class HitlRequest:
6465

6566
kind: Literal["input", "tool_confirmation", "credential"]
6667
interrupt_id: str
67-
invocation_id: Optional[str] = None
68-
author: Optional[str] = None
69-
message: Optional[str] = None
70-
payload: Optional[Any] = None
71-
response_schema: Optional[dict[str, Any]] = None
72-
original_function_call: Optional[dict[str, Any]] = None
68+
invocation_id: str | None = None
69+
author: str | None = None
70+
message: str | None = None
71+
payload: Any | None = None
72+
response_schema: dict[str, Any] | None = None
73+
original_function_call: dict[str, Any] | None = None
7374

7475

7576
def pending_hitl_requests(event: Event) -> list[HitlRequest]:
@@ -104,10 +105,10 @@ def pending_hitl_requests(event: Event) -> list[HitlRequest]:
104105
if kind is None:
105106
continue
106107
args = function_call.args or {}
107-
message: Optional[str] = None
108-
payload: Optional[Any] = None
109-
response_schema: Optional[dict[str, Any]] = None
110-
original_function_call: Optional[dict[str, Any]] = None
108+
message: str | None = None
109+
payload: Any | None = None
110+
response_schema: dict[str, Any] | None = None
111+
original_function_call: dict[str, Any] | None = None
111112
if kind == "input":
112113
message = args.get("message")
113114
payload = args.get("payload")
@@ -164,7 +165,7 @@ def hitl_input_response(interrupt_id: str, response: Any) -> types.Part:
164165

165166

166167
def hitl_confirmation_response(
167-
interrupt_id: str, *, confirmed: bool, payload: Optional[Any] = None
168+
interrupt_id: str, *, confirmed: bool, payload: Any | None = None
168169
) -> types.Part:
169170
"""Builds the message part answering a tool-confirmation request.
170171

temporalio/contrib/google_adk_agents/workflow.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import functools
44
import inspect
55
import typing
6-
from typing import TYPE_CHECKING, Any, Callable, Optional
6+
from typing import TYPE_CHECKING, Any, Callable
77

88
import temporalio.workflow
99
from temporalio import workflow
@@ -64,7 +64,7 @@ async def wrapper(*args: Any, **kw: Any):
6464
def activity_node(
6565
activity_def: Callable,
6666
*,
67-
name: Optional[str] = None,
67+
name: str | None = None,
6868
rerun_on_resume: bool = False,
6969
**kwargs: Any,
7070
) -> "FunctionNode":

tests/contrib/google_adk_agents/test_adk_dynamic_workflows.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import uuid
1919
from collections.abc import AsyncGenerator
2020
from datetime import timedelta
21-
from typing import Any, Optional
21+
from typing import Any
2222

2323
import pytest
2424
from google.adk.agents import LlmAgent
@@ -158,7 +158,7 @@ class WorkflowToolModel(BaseLlm):
158158
async def generate_content_async(
159159
self, llm_request: LlmRequest, stream: bool = False
160160
) -> AsyncGenerator[LlmResponse, None]:
161-
tool_response: Optional[types.FunctionResponse] = None
161+
tool_response: types.FunctionResponse | None = None
162162
for content in llm_request.contents:
163163
for part in content.parts or []:
164164
if part.function_response is not None:

tests/contrib/google_adk_agents/test_adk_graph_workflows.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,10 @@ def route_ticket(node_input: Any) -> Event:
123123
text = str(node_input)
124124
return Event(route="bug" if "bug" in text else "other", output=text) # type: ignore
125125

126-
def handle_bug(node_input: str) -> str:
126+
def handle_bug(node_input: str) -> str: # pyright: ignore[reportUnusedParameter]
127127
return "routed-to-bug"
128128

129-
def handle_other(node_input: str) -> str:
129+
def handle_other(node_input: str) -> str: # pyright: ignore[reportUnusedParameter]
130130
return "routed-to-other"
131131

132132
graph = Workflow(
@@ -145,10 +145,10 @@ class ParallelJoinGraphWorkflow:
145145

146146
@workflow.run
147147
async def run(self, prompt: str) -> dict[str, Any]:
148-
def make_a(node_input: Any) -> str:
148+
def make_a(node_input: Any) -> str: # pyright: ignore[reportUnusedParameter]
149149
return "alpha"
150150

151-
def make_b(node_input: Any) -> str:
151+
def make_b(node_input: Any) -> str: # pyright: ignore[reportUnusedParameter]
152152
return "beta"
153153

154154
enrich_a = activity_node(
@@ -177,7 +177,7 @@ class MultiParamActivityNodeWorkflow:
177177

178178
@workflow.run
179179
async def run(self, prompt: str) -> str:
180-
def prepare(node_input: Any) -> dict[str, str]:
180+
def prepare(node_input: Any) -> dict[str, str]: # pyright: ignore[reportUnusedParameter]
181181
return {"left": "L", "right": "R"}
182182

183183
combine = activity_node(
@@ -216,7 +216,7 @@ class TimeoutGraphWorkflow:
216216

217217
@workflow.run
218218
async def run(self, prompt: str) -> str:
219-
async def slow(node_input: Any) -> str:
219+
async def slow(node_input: Any) -> str: # pyright: ignore[reportUnusedParameter]
220220
await asyncio.sleep(5)
221221
return "never"
222222

@@ -237,7 +237,7 @@ class RetryGraphWorkflow:
237237
async def run(self, prompt: str) -> str:
238238
attempts: list[int] = []
239239

240-
def flaky(node_input: Any) -> str:
240+
def flaky(node_input: Any) -> str: # pyright: ignore[reportUnusedParameter]
241241
attempts.append(1)
242242
if len(attempts) < 2:
243243
raise RuntimeError("transient failure")
@@ -264,7 +264,7 @@ class JitteredRetryGraphWorkflow:
264264
async def run(self, prompt: str) -> str:
265265
attempts: list[int] = []
266266

267-
def flaky(node_input: Any) -> str:
267+
def flaky(node_input: Any) -> str: # pyright: ignore[reportUnusedParameter]
268268
attempts.append(1)
269269
if len(attempts) < 2:
270270
raise RuntimeError("transient failure")

tests/contrib/google_adk_agents/test_adk_hitl.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import uuid
1919
from collections.abc import AsyncGenerator
2020
from datetime import timedelta
21-
from typing import Any, Optional
21+
from typing import Any
2222

2323
import pytest
2424
from google.adk.agents import LlmAgent
@@ -327,7 +327,7 @@ async def _wait_for_pending(
327327
handle: WorkflowHandle,
328328
query: Any,
329329
count: int = 1,
330-
expected_ids: Optional[set[str]] = None,
330+
expected_ids: set[str] | None = None,
331331
) -> list[HitlRequest]:
332332
async def _poll() -> list[HitlRequest]:
333333
while True:
@@ -422,15 +422,15 @@ async def test_hitl_multiple_pending_partial_response(client: Client):
422422
task_queue=TASK_QUEUE,
423423
execution_timeout=timedelta(seconds=60),
424424
)
425-
pending = await _wait_for_pending(
425+
await _wait_for_pending(
426426
handle, MultiPendingGraphWorkflow.pending_requests, expected_ids={"a", "b"}
427427
)
428428

429429
# Answer only one; the other must stay pending.
430430
await handle.execute_update(
431431
MultiPendingGraphWorkflow.respond, args=["a", "yes-a"]
432432
)
433-
pending = await _wait_for_pending(
433+
await _wait_for_pending(
434434
handle, MultiPendingGraphWorkflow.pending_requests, expected_ids={"b"}
435435
)
436436

0 commit comments

Comments
 (0)