Repository navigation
Conversation
Signed-off-by: Roxen-AS <akash.arjun12@gmail.com>
Sun-Wukhan
left a comment
There was a problem hiding this comment.
Thanks for tracking this down. I confirmed the root cause against main: in the Union branch of convert_if_exist_pydantic_model an int value never satisfies isinstance(value, float), and the int for float exception further down is unreachable for Union annotations because the Union branch raises once the loop finishes without a match. The widening clause in the loop plus the bool exclusion in both places fixes that, and the new tests cover float | None, Optional[float], Union[float, str], and the Union[float, bool] ordering.
Two points worth a look:
-
The second hunk changes behaviour outside the Union path, and no test pins it. Because
boolis a subclass ofint, the scalar exception previously also acceptedTrueanywhere a float was expected, including through the container branches: on main,convert_if_exist_pydantic_model([True], list[float])returns[True]and the same holds for adict[str, float]value. With this PR both now raiseUnknownFunctionCallArgumentError. That looks like the right outcome, but it is a behaviour change a caller could be relying on, so could you add regression tests for thelist[float]anddict[str, float]cases so the change is deliberate and stays fixed? -
Ordering inside the Union loop: the widening clause runs before an exact type match on a later member is tried. For
Union[float, int]an int value is now claimed by the float member before the loop reachesint. The result is identical today because the conversion returns the value unchanged, so this is not a problem in practice, but if the float path ever starts coercing values (for example returningfloat(value)), the member order would silently change results. Worth a short comment at the clause noting that widening is a fallback, or trying exact matches first.
The invoke level test with Union[float, None] is a good end to end pin for the reported case.
Signed-off-by: Roxen-AS <akash.arjun12@gmail.com>
|
Thanks @Sun-Wukhan for the review! Addressed both points:
|
Summary
Fixes #3453.
In convert_if_exist_pydantic_model (google/genai/_extra_utils.py), convert_number_values_for_function_call_args normalizes whole-number floats (like 21.0) to int, and the non-Union path already accepts int for loat annotations. However, the Union branch (Optional[float], loat | None, Union[float, str], etc.) only checked isinstance(value, arg), rejecting whole-number arguments with UnknownFunctionCallArgumentError.
Changes
Testing