diff --git a/src/anthropic/_models.py b/src/anthropic/_models.py index dc00516b..98ea7239 100644 --- a/src/anthropic/_models.py +++ b/src/anthropic/_models.py @@ -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: diff --git a/tests/test_models.py b/tests/test_models.py index 195f2307..94cb47a2 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -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"]