Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/mypy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:
- main

env:
SPEAKEASY_VERSION: v2.959.1
SPEAKEASY_VERSION: v2.960.7

jobs:
mypy:
Expand Down
18 changes: 9 additions & 9 deletions google/genai/_gaos/utils/annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,24 @@ def get_discriminator(model: Any, fieldname: str, key: str) -> str:
"""
upper_fieldname = fieldname.upper()

def to_discriminator(value: Any) -> str:
"""Convert a discriminator value to a string, using the value of enum members."""
if isinstance(value, Enum):
return f"{value.value}"
return f"{value}"

def get_field_discriminator(field: Any) -> Optional[str]:
"""Search for the discriminator attribute in a given field."""

if isinstance(field, dict):
if key in field:
return f"{field[key]}"
return to_discriminator(field[key])

if hasattr(field, fieldname):
attr = getattr(field, fieldname)
if isinstance(attr, Enum):
return f"{attr.value}"
return f"{attr}"
return to_discriminator(getattr(field, fieldname))

if hasattr(field, upper_fieldname):
attr = getattr(field, upper_fieldname)
if isinstance(attr, Enum):
return f"{attr.value}"
return f"{attr}"
return to_discriminator(getattr(field, upper_fieldname))

return None

Expand Down
7 changes: 6 additions & 1 deletion google/genai/_gaos/utils/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@ def get_body_content(req: httpx.Request) -> str:


def get_default_logger() -> Logger:
if os.getenv("GOOGLE_GENAI_DEBUG"):
if os.getenv("GOOGLE_GENAI_DEBUG", "").strip().lower() in (
"true",
"1",
"yes",
"on",
):
logging.basicConfig(level=logging.DEBUG)
return logging.getLogger("google.genai")
return NoOpLogger()
29 changes: 29 additions & 0 deletions google/genai/tests/client/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright 2026 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

"""Shared fixtures for client tests."""

import pytest

from ... import _api_client as api_client


@pytest.fixture(autouse=True)
def reset_has_aiohttp():
# Some client tests override the module-level `has_aiohttp` flag; restore it
# so the override does not leak into later tests on the same pytest worker.
original = api_client.has_aiohttp
yield
api_client.has_aiohttp = original
6 changes: 0 additions & 6 deletions google/genai/tests/client/test_async_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,6 @@ def responses() -> api_client.HttpResponse:
)


@pytest.fixture(autouse=True)
def reset_has_aiohttp():
yield
api_client.has_aiohttp = False


def test_invalid_response_stream_type(responses: api_client.HttpResponse):
"""Tests that an invalid response stream type raises an error."""
api_client.has_aiohttp = False
Expand Down
8 changes: 2 additions & 6 deletions google/genai/tests/client/test_client_initialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,6 @@
)


@pytest.fixture(autouse=True)
def reset_has_aiohttp():
yield
api_client.has_aiohttp = False


def test_ml_dev_from_gemini_env_only(monkeypatch):
api_key = "gemini_api_key"
monkeypatch.setenv("GEMINI_API_KEY", api_key)
Expand Down Expand Up @@ -1199,6 +1193,8 @@ def test_client_ssl_context_explicit_initialization_async_args():

def test_client_initializes_httpx_clients_vertex_and_mldev():
"""Verifies both Vertex and MLDev clients initialize non-null httpx clients with timeout=None."""
# Keep the async path on httpx even when aiohttp is installed.
api_client.has_aiohttp = False
mldev_client = Client(api_key="fake-api-key")
assert mldev_client._api_client._httpx_client is not None
assert mldev_client._api_client._async_httpx_client is not None
Expand Down
2 changes: 1 addition & 1 deletion google/genai/tests/client/test_custom_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def test_constructor_with_httpx_clients():
assert not vertexai_client.models._api_client._async_httpx_client.trust_env
# Expect aiohttp to be disabled when httpx clients are provided, regardless of
# whether aiohttp is installed.
assert not mldev_client.models._api_client._use_aiohttp()
assert not vertexai_client.models._api_client._use_aiohttp()


# Aiohttp
Expand Down
3 changes: 3 additions & 0 deletions google/genai/tests/client/test_httpx2_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,9 @@ async def test_aclose_when_async_httpx_client_is_none(monkeypatch):

def test_vertexai_with_httpx2(monkeypatch):
monkeypatch.setenv('GOOGLE_GENAI_HTTP_CLIENT', 'httpx2')
# Keep the async path on httpx2 even when aiohttp is installed.
target_api_client = getattr(api_client, 'public_api_client', api_client)
monkeypatch.setattr(target_api_client, 'has_aiohttp', False)
client = Client(
vertexai=True,
project='fake-project',
Expand Down
6 changes: 0 additions & 6 deletions google/genai/tests/client/test_retries.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,6 @@
)


@pytest.fixture(autouse=True)
def reset_has_aiohttp():
yield
api_client.has_aiohttp = False


def _final_codes(retried_codes: Sequence[int] = _RETRIED_CODES):
return [code for code in range(100, 600) if code not in retried_codes]

Expand Down
Loading