Skip to content

Commit 5301ffa

Browse files
xuanyang15copybara-github
authored andcommitted
fix: Address mypy failures in google_api_tool/
Co-authored-by: Xuan Yang <xygoogle@google.com> PiperOrigin-RevId: 943533056
1 parent 9787e97 commit 5301ffa

3 files changed

Lines changed: 14 additions & 2 deletions

File tree

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,9 @@ python_version = "3.11"
306306
disable_error_code = [ "import-not-found", "import-untyped", "unused-ignore" ]
307307
strict = true
308308
plugins = [ "pydantic.mypy" ]
309+
overrides = [ { module = [
310+
"google.auth.*",
311+
], ignore_missing_imports = true, follow_imports = "skip" } ]
309312

310313
[tool.pytest]
311314
ini_options.testpaths = [ "tests" ]

src/google/adk/tools/google_api_tool/google_api_toolset.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,12 @@ def __init__(
9090
cert_path, key_path, passphrase = self._mtls_certs.get_certs()
9191
if cert_path and key_path and passphrase:
9292

93-
def client_factory():
94-
return httpx.AsyncClient(cert=(cert_path, key_path, passphrase))
93+
def client_factory() -> httpx.AsyncClient:
94+
if passphrase:
95+
return httpx.AsyncClient(
96+
cert=(cert_path, key_path, passphrase) # type: ignore[arg-type]
97+
)
98+
return httpx.AsyncClient(cert=(cert_path, key_path))
9599

96100
self._httpx_client_factory = client_factory
97101

src/google/adk/tools/google_api_tool/googleapi_to_openapi_converter.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ def convert(self) -> Dict[str, Any]:
130130
if not self._google_api_spec:
131131
self.fetch_google_api_spec()
132132

133+
if self._google_api_spec is None:
134+
raise RuntimeError("Failed to initialize Google API specification.")
135+
133136
# Convert basic API information
134137
self._convert_info()
135138

@@ -170,6 +173,8 @@ def _convert_info(self) -> None:
170173

171174
def _convert_servers(self) -> None:
172175
"""Convert server information."""
176+
if self._google_api_spec is None:
177+
raise RuntimeError("API spec must be initialized before conversion.")
173178
use_client_cert = getattr(self, "_use_client_cert", False)
174179
if use_client_cert and "mtlsRootUrl" in self._google_api_spec:
175180
root_url = self._google_api_spec["mtlsRootUrl"]

0 commit comments

Comments
 (0)