Skip to content

Commit e290f46

Browse files
committed
fix: Remove deprecated _UnionGenericAlias to support Python 3.14+
Replace usage of private typing._UnionGenericAlias (deprecated in Python 3.14, removed in 3.17) with tuple-based isinstance checks using type(Union[int, str]). This maintains compatibility with both old-style Union[T1, T2] and new-style T1 | T2 syntax while avoiding deprecation warnings.
1 parent b61163f commit e290f46

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

google/genai/_automatic_function_calling_util.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626

2727

2828
if sys.version_info >= (3, 10):
29-
VersionedUnionType = builtin_types.UnionType
29+
VersionedUnionType = (builtin_types.UnionType, type(Union[int, str]))
3030
else:
31-
VersionedUnionType = typing._UnionGenericAlias # type: ignore[attr-defined]
31+
VersionedUnionType = (type(Union[int, str]),)
3232

3333

3434
__all__ = [

google/genai/_transformers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@
4242
logger = logging.getLogger('google_genai._transformers')
4343

4444
if sys.version_info >= (3, 10):
45-
VersionedUnionType = builtin_types.UnionType
45+
VersionedUnionType = (builtin_types.UnionType, type(Union[int, str]))
4646
_UNION_TYPES = (typing.Union, builtin_types.UnionType)
4747
from typing import TypeGuard
4848
else:
49-
VersionedUnionType = typing._UnionGenericAlias # type: ignore[attr-defined]
49+
VersionedUnionType = (type(Union[int, str]),)
5050
_UNION_TYPES = (typing.Union,)
5151
from typing_extensions import TypeGuard
5252

google/genai/types.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import sys
2626
import types as builtin_types
2727
import typing
28-
from typing import Any, Callable, Dict, List, Literal, Optional, Sequence, Union, _UnionGenericAlias # type: ignore
28+
from typing import Any, Callable, Dict, List, Literal, Optional, Sequence, Union
2929
import pydantic
3030
from pydantic import ConfigDict, Field, PrivateAttr, model_validator
3131
from typing_extensions import Self, TypedDict
@@ -40,11 +40,11 @@
4040

4141
if sys.version_info >= (3, 10):
4242
# Supports both Union[t1, t2] and t1 | t2
43-
VersionedUnionType = Union[builtin_types.UnionType, _UnionGenericAlias]
43+
VersionedUnionType = (builtin_types.UnionType, type(Union[int, str]))
4444
_UNION_TYPES = (typing.Union, builtin_types.UnionType)
4545
else:
4646
# Supports only Union[t1, t2]
47-
VersionedUnionType = _UnionGenericAlias
47+
VersionedUnionType = (type(Union[int, str]),)
4848
_UNION_TYPES = (typing.Union,)
4949

5050
_is_pillow_image_imported = False

0 commit comments

Comments
 (0)