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
2 changes: 1 addition & 1 deletion src/anthropic/_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ def construct_type(*, value: object, type_: object, metadata: Optional[List[Any]
if not is_list(value):
return value

inner_type = args[0] # List[inner_type]
inner_type = args[0] if args else object # List[inner_type] or bare list
return [construct_type(value=entry, type_=inner_type) for entry in value]

if origin == float:
Expand Down
7 changes: 6 additions & 1 deletion tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1014,4 +1014,9 @@ class Model(BaseModel):

# falls back to list of chars rather than calling str(["h", "e", "l", "l", "o"])
assert m.data["items"] == ["h", "e", "l", "l", "o"]
assert m.model_dump()["data"]["items"] == ["h", "e", "l", "l", "o"]


def test_construct_type_bare_list() -> None:
# Bare list (no type parameter) must not raise IndexError
result = construct_type(value=["a", "b", "c"], type_=list)
assert result == ["a", "b", "c"]