Skip to content

Commit b080641

Browse files
committed
fix: Expand VersionedUnionType tuple in SchemaUnion definition
Fixes ImportError caused by passing a tuple to Union[]. The previous commit (e290f46) changed VersionedUnionType from a Union type to a tuple for isinstance checks, but SchemaUnion was still trying to use it as a Union argument. This expands the tuple elements individually for Python 3.10+ (UnionType + _UnionGenericAlias) and Python < 3.10 (_UnionGenericAlias only). Error: TypeError: Union[arg, ...]: each arg must be a type. Got (<class 'types.UnionType'>, <class 'typing._UnionGenericAlias'>).
1 parent aa57b50 commit b080641

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

google/genai/types.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4251,9 +4251,14 @@ class ToolDict(TypedDict, total=False):
42514251
ToolListUnion = list[ToolUnion]
42524252
ToolListUnionDict = list[ToolUnionDict]
42534253

4254-
SchemaUnion = Union[
4255-
dict[Any, Any], type, Schema, builtin_types.GenericAlias, VersionedUnionType # type: ignore[valid-type]
4256-
]
4254+
if sys.version_info >= (3, 10):
4255+
SchemaUnion = Union[
4256+
dict[Any, Any], type, Schema, builtin_types.GenericAlias, builtin_types.UnionType, type(Union[int, str])
4257+
]
4258+
else:
4259+
SchemaUnion = Union[
4260+
dict[Any, Any], type, Schema, builtin_types.GenericAlias, type(Union[int, str])
4261+
]
42574262
SchemaUnionDict = Union[SchemaUnion, SchemaDict]
42584263

42594264

0 commit comments

Comments
 (0)