Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/marvin/utilities/jsonschema.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,13 @@ def create_array_type(
if isinstance(items, list):
# Handle positional item schemas
item_types = [schema_to_type(s, schemas) for s in items]
from typing import Union
if not item_types:
base = list[Any]
else:
from typing import Union

combined = Union[tuple(item_types)]
base = list[combined]
combined = Union[tuple(item_types)] if len(item_types) > 1 else item_types[0]
base = list[combined]
else:
# Handle single item schema
item_type = schema_to_type(items, schemas)
Expand Down
5 changes: 5 additions & 0 deletions tests/basic/utilities/test_jsonschema.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,11 @@ def test_unique_items_converts_duplicates(self, unique_items_array):
result = validator.validate_python(["a", "a", "b"])
assert result == {"a", "b"}

def test_empty_items_list_does_not_crash(self):
# items=[] (empty tuple schema) must not raise TypeError from Union[()]
result = jsonschema_to_type({"type": "array", "items": []})
assert TypeAdapter(result).validate_python([1, "x", None]) == [1, "x", None]


class TestObjectTypes:
"""Test suite for object validation."""
Expand Down
Loading