Skip to content

Commit d62ea96

Browse files
lint
1 parent 1187d82 commit d62ea96

7 files changed

Lines changed: 58 additions & 42 deletions

File tree

temporalio/contrib/google_gemini_sdk/_gemini_activity.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from __future__ import annotations
1010

1111
from collections.abc import Sequence
12-
from typing import Any, Callable, Optional
12+
from typing import Any, Callable
1313

1414
import google.auth.credentials
1515
from google.genai import Client as GeminiClient
@@ -49,7 +49,7 @@ class GeminiApiCaller:
4949
def __init__(
5050
self,
5151
client: GeminiClient,
52-
credentials: Optional[google.auth.credentials.Credentials] = None,
52+
credentials: google.auth.credentials.Credentials | None = None,
5353
) -> None:
5454
self._client = client
5555
self._credentials = credentials

temporalio/contrib/google_gemini_sdk/_gemini_plugin.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from __future__ import annotations
44

55
import dataclasses
6-
from typing import Optional
76

87
import google.auth.credentials
98
from google.genai import Client as GeminiClient
@@ -64,7 +63,7 @@ class GeminiPlugin(SimplePlugin):
6463
def __init__(
6564
self,
6665
client: GeminiClient,
67-
extra_credentials: Optional[google.auth.credentials.Credentials] = None,
66+
extra_credentials: google.auth.credentials.Credentials | None = None,
6867
) -> None:
6968
"""Initialize the Gemini plugin.
7069

temporalio/contrib/google_gemini_sdk/_temporal_api_client.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from __future__ import annotations
1616

1717
from datetime import timedelta
18-
from typing import Any, Optional
18+
from typing import Any
1919

2020
from google.genai import types
2121
from google.genai._api_client import BaseApiClient
@@ -56,7 +56,7 @@ class _SerializableHttpOptions(BaseModel):
5656
)
5757

5858

59-
def _validate_http_options(http_options: Optional[HttpOptions]) -> None:
59+
def _validate_http_options(http_options: HttpOptions | None) -> None:
6060
"""Raise if http_options contains non-serializable fields."""
6161
if http_options is None:
6262
return
@@ -150,7 +150,7 @@ class TemporalApiClient(BaseApiClient):
150150
All actual HTTP calls are dispatched via ``workflow.execute_activity``.
151151
"""
152152

153-
def __init__(
153+
def __init__( # pyright: ignore[reportMissingSuperCall]
154154
self,
155155
*,
156156
vertexai: bool = False,
@@ -189,7 +189,7 @@ def __del__(self) -> None:
189189

190190
@staticmethod
191191
def _process_http_options(
192-
http_options: Optional[HttpOptionsOrDict],
192+
http_options: HttpOptionsOrDict | None,
193193
config: ActivityConfig,
194194
) -> _SerializableHttpOptions | None:
195195
"""Validate and extract serializable per-request HTTP options.
@@ -243,7 +243,7 @@ async def async_request(
243243
http_method: str,
244244
path: str,
245245
request_dict: dict[str, object],
246-
http_options: Optional[HttpOptionsOrDict] = None,
246+
http_options: HttpOptionsOrDict | None = None,
247247
) -> SdkHttpResponse:
248248
config: ActivityConfig = {**self._activity_config}
249249
if "summary" not in config:
@@ -271,7 +271,7 @@ def request(
271271
http_method: str,
272272
path: str,
273273
request_dict: dict[str, object],
274-
http_options: Optional[HttpOptionsOrDict] = None,
274+
http_options: HttpOptionsOrDict | None = None,
275275
) -> SdkHttpResponse:
276276
raise RuntimeError(
277277
"Synchronous requests are not supported in Temporal workflows. "
@@ -283,7 +283,7 @@ def request_streamed(
283283
http_method: str,
284284
path: str,
285285
request_dict: dict[str, object],
286-
http_options: Optional[HttpOptionsOrDict] = None,
286+
http_options: HttpOptionsOrDict | None = None,
287287
) -> Any:
288288
raise RuntimeError(
289289
"Synchronous streaming is not supported in Temporal workflows. "
@@ -295,7 +295,7 @@ async def async_request_streamed(
295295
http_method: str,
296296
path: str,
297297
request_dict: dict[str, object],
298-
http_options: Optional[HttpOptionsOrDict] = None,
298+
http_options: HttpOptionsOrDict | None = None,
299299
) -> Any:
300300
config: ActivityConfig = {**self._activity_config}
301301
if "summary" not in config:

temporalio/contrib/google_gemini_sdk/_temporal_file_search_stores.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,9 @@
1111
import io
1212
import os
1313
from datetime import timedelta
14-
from typing import Optional, Union
1514

1615
from google.genai import types
1716
from google.genai.file_search_stores import AsyncFileSearchStores
18-
from google.genai.types import HttpOptions
1917

2018
from temporalio import workflow as temporal_workflow
2119
from temporalio.contrib.google_gemini_sdk._temporal_api_client import (
@@ -51,8 +49,8 @@ async def upload_to_file_search_store(
5149
self,
5250
*,
5351
file_search_store_name: str,
54-
file: Union[str, "os.PathLike[str]", io.IOBase],
55-
config: Optional[types.UploadToFileSearchStoreConfigOrDict] = None,
52+
file: str | os.PathLike[str] | io.IOBase,
53+
config: types.UploadToFileSearchStoreConfigOrDict | None = None,
5654
) -> types.UploadToFileSearchStoreOperation:
5755
"""Upload a file to a file search store via a Temporal activity.
5856

temporalio/contrib/google_gemini_sdk/_temporal_files.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,12 @@
1111
import io
1212
import os
1313
from datetime import timedelta
14-
from typing import TYPE_CHECKING, Optional, Union
14+
from typing import TYPE_CHECKING
1515

1616
if TYPE_CHECKING:
1717
import google.auth.credentials
1818
from google.genai import types
1919
from google.genai.files import AsyncFiles
20-
from google.genai.types import HttpOptions
2120

2221
from temporalio import workflow as temporal_workflow
2322
from temporalio.contrib.google_gemini_sdk._temporal_api_client import (
@@ -53,8 +52,8 @@ def __init__(
5352
async def upload(
5453
self,
5554
*,
56-
file: Union[str, "os.PathLike[str]", io.IOBase],
57-
config: Optional[types.UploadFileConfigOrDict] = None,
55+
file: str | os.PathLike[str] | io.IOBase,
56+
config: types.UploadFileConfigOrDict | None = None,
5857
) -> types.File:
5958
"""Upload a file via a Temporal activity.
6059
@@ -93,8 +92,8 @@ async def upload(
9392
async def download(
9493
self,
9594
*,
96-
file: Union[str, types.File],
97-
config: Optional[types.DownloadFileConfigOrDict] = None,
95+
file: str | types.File,
96+
config: types.DownloadFileConfigOrDict | None = None,
9897
) -> bytes:
9998
"""Download a file via a Temporal activity."""
10099
act_config: ActivityConfig = {**self._activity_config}
@@ -128,7 +127,7 @@ async def register_files(
128127
*,
129128
auth: google.auth.credentials.Credentials,
130129
uris: list[str],
131-
config: Optional[types.RegisterFilesConfigOrDict] = None,
130+
config: types.RegisterFilesConfigOrDict | None = None,
132131
) -> types.RegisterFilesResponse:
133132
"""Register GCS files via a Temporal activity.
134133

temporalio/contrib/google_gemini_sdk/justfile

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,38 @@ worker:
99

1010
query q="What's the weather right now?":
1111
uv run python first_class_example/start_workflow.py "{{q}}"
12+
13+
embed-worker:
14+
uv run python embed_example/worker.py
15+
16+
embed prompt="A serene mountain lake at sunset with pine trees":
17+
uv run python embed_example/start_workflow.py "{{prompt}}"
18+
19+
vibe-worker:
20+
uv run python vibe_convergence_example/worker.py
21+
22+
set positional-arguments
23+
24+
vibe *ARGS:
25+
uv run python vibe_convergence_example/start_workflow.py "$@"
26+
27+
spy-worker:
28+
uv run python i_spy_example/worker.py
29+
30+
spy:
31+
uv run python i_spy_example/start_workflow.py
32+
33+
file-worker:
34+
uv run python file_upload_example/worker.py
35+
36+
file q="Summarize the key financial metrics and top 3 risks from this report.":
37+
uv run python file_upload_example/start_workflow.py "{{q}}"
38+
39+
file-store:
40+
uv run python file_upload_example/start_workflow.py --store
41+
42+
chat-worker:
43+
uv run python chat_example/worker.py
44+
45+
chat topic="recursion in programming":
46+
uv run python chat_example/start_workflow.py "{{topic}}"

tests/contrib/google_gemini_sdk/test_gemini.py

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,12 +1068,7 @@ def _apply_plugin_with_mock_client(client: Client, mock_responses: list[str]) ->
10681068

10691069
call_state = {"index": 0}
10701070

1071-
async def fake_async_request(
1072-
http_method: str,
1073-
path: str,
1074-
request_dict: dict[str, object],
1075-
http_options: Any = None,
1076-
) -> SdkHttpResponse:
1071+
async def fake_async_request(*_args: Any, **_kwargs: Any) -> SdkHttpResponse:
10771072
idx = call_state["index"]
10781073
call_state["index"] += 1
10791074
if idx >= len(mock_responses):
@@ -1086,12 +1081,7 @@ async def fake_async_request(
10861081
body=mock_responses[idx],
10871082
)
10881083

1089-
async def fake_async_request_streamed(
1090-
http_method: str,
1091-
path: str,
1092-
request_dict: dict[str, object],
1093-
http_options: Any = None,
1094-
) -> Any:
1084+
async def fake_async_request_streamed(*_args: Any, **_kwargs: Any) -> Any:
10951085
idx = call_state["index"]
10961086
call_state["index"] += 1
10971087
if idx >= len(mock_responses):
@@ -1190,14 +1180,9 @@ async def test_register_files_without_credentials_fails(client: Client):
11901180
)
11911181

11921182
# The error is nested: WorkflowFailureError → ActivityError → ApplicationError
1193-
cause: BaseException | None = exc_info.value.cause
1194-
while (
1195-
cause is not None
1196-
and hasattr(cause, "__cause__")
1197-
and cause.__cause__ is not None
1198-
):
1183+
cause = exc_info.value.cause
1184+
while cause.__cause__ is not None:
11991185
cause = cause.__cause__
1200-
assert cause is not None
12011186
assert "No credentials available for register_files" in str(cause)
12021187

12031188

0 commit comments

Comments
 (0)