From cb1408b06c573060f1593023ca320fde9a4fb5f6 Mon Sep 17 00:00:00 2001 From: Ayush Agrawal Date: Sat, 24 Oct 2026 11:40:53 -0700 Subject: [PATCH] feat: Add support for Python 3.15. PiperOrigin-RevId: 1006372742 --- .github/workflows/import.yml | 2 +- .github/workflows/mypy.yml | 2 +- google/genai/types.py | 20 +++++++++++++------- pyproject.toml | 1 + requirements.txt | 9 ++++++--- 5 files changed, 22 insertions(+), 12 deletions(-) diff --git a/.github/workflows/import.yml b/.github/workflows/import.yml index 8a110616ba..08e11ec02f 100644 --- a/.github/workflows/import.yml +++ b/.github/workflows/import.yml @@ -13,7 +13,7 @@ jobs: strategy: matrix: - python-version: ['3.10', '3.11', '3.12', '3.13', '3.14'] + python-version: ['3.10', '3.11', '3.12', '3.13', '3.14', '3.15'] steps: - name: Checkout repository diff --git a/.github/workflows/mypy.yml b/.github/workflows/mypy.yml index 40a19eb98b..c422de85f6 100644 --- a/.github/workflows/mypy.yml +++ b/.github/workflows/mypy.yml @@ -17,7 +17,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ['3.10', '3.11', '3.12', '3.13', '3.14'] + python-version: ['3.10', '3.11', '3.12', '3.13', '3.14', '3.15'] steps: - name: Checkout code diff --git a/google/genai/types.py b/google/genai/types.py index 70fdf92270..7a18e2a6d6 100644 --- a/google/genai/types.py +++ b/google/genai/types.py @@ -25,7 +25,7 @@ import sys import types as builtin_types import typing -from typing import Annotated, Any, Callable, Dict, List, Literal, Optional, Sequence, Union, _UnionGenericAlias # type: ignore +from typing import Annotated, Any, Callable, Dict, List, Literal, Optional, Sequence, Union import pydantic from pydantic import ConfigDict, Field, PrivateAttr, WrapValidator, model_validator from typing_extensions import Self, TypedDict @@ -37,14 +37,20 @@ _UploadToFileSearchStoreOperation_from_mldev, ) -if sys.version_info >= (3, 10): - # Supports both Union[t1, t2] and t1 | t2 - VersionedUnionType = Union[builtin_types.UnionType, _UnionGenericAlias] +if typing.TYPE_CHECKING: + # Type checkers have always seen this as Any, which lets SchemaUnion accept + # any schema (e.g. Optional[X]). Keep it that way. + VersionedUnionType = Any + _UNION_TYPES = (typing.Union, builtin_types.UnionType) +elif sys.version_info >= (3, 14): + # Union[t1, t2] and t1 | t2 both create builtin_types.UnionType, and + # typing._UnionGenericAlias is deprecated. + VersionedUnionType = builtin_types.UnionType _UNION_TYPES = (typing.Union, builtin_types.UnionType) else: - # Supports only Union[t1, t2] - VersionedUnionType = _UnionGenericAlias - _UNION_TYPES = (typing.Union,) + # Supports both Union[t1, t2] and t1 | t2 + VersionedUnionType = Union[builtin_types.UnionType, typing._UnionGenericAlias] # type: ignore + _UNION_TYPES = (typing.Union, builtin_types.UnionType) _is_pillow_image_imported = False if typing.TYPE_CHECKING: diff --git a/pyproject.toml b/pyproject.toml index 0ca787c15a..d0396e651d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -21,6 +21,7 @@ classifiers = [ "Programming Language :: Python :: 3.12", "Programming Language :: Python :: 3.13", "Programming Language :: Python :: 3.14", + "Programming Language :: Python :: 3.15", "Topic :: Internet", "Topic :: Software Development :: Libraries :: Python Modules", ] diff --git a/requirements.txt b/requirements.txt index 4583be06a3..c8f6e0aa4d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -12,13 +12,16 @@ google-auth==2.56.0 idna==3.18 iniconfig==2.0.0 packaging==24.2 -pillow==11.0.0 +pillow==11.0.0; python_version < '3.15' +pillow==12.3.0; python_version >= '3.15' pluggy==1.5.0 py==1.11.0 pyasn1==0.6.1 pyasn1_modules==0.4.1 -pydantic==2.12.0 -pydantic_core==2.41.1 +pydantic==2.12.0; python_version < '3.15' +pydantic==2.14.1; python_version >= '3.15' +pydantic_core==2.41.1; python_version < '3.15' +pydantic_core==2.50.1; python_version >= '3.15' pyopenssl==24.2.1 pytest==8.3.4 pytest-asyncio==0.25.0