From acfaadb7edc84c226fa4ef2782fdfbaafbbfbf3a Mon Sep 17 00:00:00 2001 From: lars20070 Date: Fri, 14 Nov 2025 16:50:04 +0100 Subject: [PATCH 1/3] check for None --- pydantic_ai_slim/pydantic_ai/providers/google.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pydantic_ai_slim/pydantic_ai/providers/google.py b/pydantic_ai_slim/pydantic_ai/providers/google.py index d0de4bcc4f..025447e8e5 100644 --- a/pydantic_ai_slim/pydantic_ai/providers/google.py +++ b/pydantic_ai_slim/pydantic_ai/providers/google.py @@ -219,5 +219,6 @@ class _NonClosingApiClient(BaseApiClient): async def aclose(self) -> None: # The original implementation also calls `await self._async_httpx_client.aclose()`, but we don't want to close our `cached_async_http_client` or the one the user passed in. # TODO: Remove once https://github.com/googleapis/python-genai/issues/1566 is solved. - if self._aiohttp_session: + session = getattr(self, '_aiohttp_session', None) + if session: await self._aiohttp_session.close() # pragma: no cover From 97fa40f14ce6c1630b21f46be410d38220da60be Mon Sep 17 00:00:00 2001 From: lars20070 Date: Fri, 14 Nov 2025 17:06:35 +0100 Subject: [PATCH 2/3] fix linter --- pydantic_ai_slim/pydantic_ai/providers/google.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/pydantic_ai_slim/pydantic_ai/providers/google.py b/pydantic_ai_slim/pydantic_ai/providers/google.py index 025447e8e5..8fbf2101b2 100644 --- a/pydantic_ai_slim/pydantic_ai/providers/google.py +++ b/pydantic_ai_slim/pydantic_ai/providers/google.py @@ -28,11 +28,13 @@ class GoogleProvider(Provider[Client]): @property def name(self) -> str: - return 'google-vertex' if self._client._api_client.vertexai else 'google-gla' # type: ignore[reportPrivateUsage] + # type: ignore[reportPrivateUsage] + return 'google-vertex' if self._client._api_client.vertexai else 'google-gla' @property def base_url(self) -> str: - return str(self._client._api_client._http_options.base_url) # type: ignore[reportPrivateUsage] + # type: ignore[reportPrivateUsage] + return str(self._client._api_client._http_options.base_url) @property def client(self) -> Client: @@ -220,5 +222,5 @@ async def aclose(self) -> None: # The original implementation also calls `await self._async_httpx_client.aclose()`, but we don't want to close our `cached_async_http_client` or the one the user passed in. # TODO: Remove once https://github.com/googleapis/python-genai/issues/1566 is solved. session = getattr(self, '_aiohttp_session', None) - if session: - await self._aiohttp_session.close() # pragma: no cover + if session is not None: + await session.close() # pragma: no cover From 549dcc92c13967a51e7ab0d287eba8d33db0297c Mon Sep 17 00:00:00 2001 From: lars20070 Date: Fri, 14 Nov 2025 17:12:22 +0100 Subject: [PATCH 3/3] revert formatting --- pydantic_ai_slim/pydantic_ai/providers/google.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/pydantic_ai_slim/pydantic_ai/providers/google.py b/pydantic_ai_slim/pydantic_ai/providers/google.py index 8fbf2101b2..a4ba0c5a3b 100644 --- a/pydantic_ai_slim/pydantic_ai/providers/google.py +++ b/pydantic_ai_slim/pydantic_ai/providers/google.py @@ -28,13 +28,11 @@ class GoogleProvider(Provider[Client]): @property def name(self) -> str: - # type: ignore[reportPrivateUsage] - return 'google-vertex' if self._client._api_client.vertexai else 'google-gla' + return 'google-vertex' if self._client._api_client.vertexai else 'google-gla' # type: ignore[reportPrivateUsage] @property def base_url(self) -> str: - # type: ignore[reportPrivateUsage] - return str(self._client._api_client._http_options.base_url) + return str(self._client._api_client._http_options.base_url) # type: ignore[reportPrivateUsage] @property def client(self) -> Client: