Skip to content

Commit cc8973a

Browse files
refactor: hoist Optional None check before Pydantic branch
1 parent 6fd8dba commit cc8973a

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/google/adk/tools/function_tool.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,14 @@ def _preprocess_args(
138138
target_type = non_none_types[0]
139139
is_optional = len(union_args) != len(non_none_types)
140140

141+
# Skip None values only for Optional params
142+
if args[param_name] is None and is_optional:
143+
continue
144+
141145
# Pydantic models: keep existing graceful-failure behavior
142146
if inspect.isclass(target_type) and issubclass(
143147
target_type, pydantic.BaseModel
144148
):
145-
if args[param_name] is None and is_optional:
146-
continue
147149
if not isinstance(args[param_name], target_type):
148150
try:
149151
converted_args[param_name] = target_type.model_validate(
@@ -158,10 +160,6 @@ def _preprocess_args(
158160
)
159161
continue
160162

161-
# Skip None values only for Optional params
162-
if args[param_name] is None and is_optional:
163-
continue
164-
165163
# Validate and coerce all other annotated types using TypeAdapter.
166164
# This handles primitives (int, float, str, bool), enums, and
167165
# container types (list[int], dict[str, float], etc.).

0 commit comments

Comments
 (0)