File tree Expand file tree Collapse file tree 1 file changed +10
-2
lines changed
Expand file tree Collapse file tree 1 file changed +10
-2
lines changed Original file line number Diff line number Diff line change 1616
1717import inspect
1818import logging
19+ import sys
1920from typing import Any
2021from typing import Callable
2122from typing import get_args
2223from typing import get_origin
2324from typing import Optional
2425from typing import Union
2526
27+ if sys .version_info >= (3 , 10 ):
28+ from types import UnionType
29+
30+ _UNION_TYPES = (Union , UnionType )
31+ else :
32+ _UNION_TYPES = (Union ,)
33+
2634from google .genai import types
2735import pydantic
2836from typing_extensions import override
@@ -130,8 +138,8 @@ def _preprocess_args(
130138 target_type = param .annotation
131139 is_optional = False
132140
133- # Handle Optional[T] (Union[T, None]) - unwrap to get inner type
134- if get_origin (param .annotation ) is Union :
141+ # Handle Optional[T] (Union[T, None]) and T | None (Python 3.10+)
142+ if get_origin (param .annotation ) in _UNION_TYPES :
135143 union_args = get_args (param .annotation )
136144 non_none_types = [arg for arg in union_args if arg is not type (None )]
137145 if len (non_none_types ) == 1 :
You can’t perform that action at this time.
0 commit comments