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

_, items_type = get_args(type_) # Dict[_, items_type]
args = get_args(type_)
items_type = args[1] if args else object # Dict[_, items_type]; plain dict has no args
return {key: construct_type(value=item, type_=items_type) for key, item in value.items()}

if (
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_dict() -> None:
# plain `dict` with no type parameters should not raise ValueError
result = construct_type(value={"key": "value"}, type_=dict)
assert result == {"key": "value"}