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/openai/_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,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 len(args) >= 2 else object
return {key: construct_type(value=item, type_=items_type) for key, item in value.items()}

if (
Expand Down
6 changes: 6 additions & 0 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_dict() -> None:
value = {"key": "value"}

assert construct_type(value=value, type_=dict) == value