From 7f1c9f8f50b27cc499038c27732274b0b9d0a1f0 Mon Sep 17 00:00:00 2001 From: nightcityblade Date: Tue, 30 Jun 2026 23:11:44 +0800 Subject: [PATCH] fix: handle bare list in construct_type --- src/anthropic/_models.py | 2 +- tests/test_models.py | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/anthropic/_models.py b/src/anthropic/_models.py index 2d979355a..bccf9761e 100644 --- a/src/anthropic/_models.py +++ b/src/anthropic/_models.py @@ -588,7 +588,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 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 494ad8d45..9bca1145b 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -961,3 +961,9 @@ def __getattr__(self, attr: str) -> Item: ... assert model.a.prop == 1 assert isinstance(model.a, Item) assert model.other == "foo" + + +def test_construct_type_with_bare_list() -> None: + value = ["a", "b", "c"] + + assert construct_type(value=value, type_=list) == value