Skip to content

Commit d60ac69

Browse files
vivekjmcopybara-github
authored andcommitted
chore: Add coverage for pipe union list annotations
Merge #6160 Add regression coverage for optional list parameters written with Python pipe union syntax, covering the List[str] | None = None signature shape. Refs #3591. PiperOrigin-RevId: 941157723
1 parent e360241 commit d60ac69

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

tests/unittests/tools/test_function_tool_with_import_annotations.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,26 @@ def test_function(str_param: str, int_param: int, any_param: Any) -> str:
159159
assert declaration.response.type == types.Type.STRING
160160

161161

162+
def test_pipe_union_list_annotation_parameter_vertex():
163+
"""Test function with pipe union list parameter annotation."""
164+
165+
def test_function(file_patterns: list[str] | None = None) -> None:
166+
"""A test function that accepts optional file patterns."""
167+
pass
168+
169+
declaration = _automatic_function_calling_util.from_function_with_options(
170+
test_function, GoogleLLMVariant.VERTEX_AI
171+
)
172+
173+
assert declaration.name == 'test_function'
174+
assert declaration.parameters.type == 'OBJECT'
175+
file_patterns_schema = declaration.parameters.properties['file_patterns']
176+
assert file_patterns_schema.type == types.Type.ARRAY
177+
assert file_patterns_schema.items.type == types.Type.STRING
178+
assert file_patterns_schema.nullable
179+
assert declaration.parameters.required == []
180+
181+
162182
def test_string_annotation_no_params_vertex():
163183
"""Test function with no parameters but string annotation return."""
164184

0 commit comments

Comments
 (0)