Skip to content
Closed
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: 3 additions & 0 deletions src/openai/_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,9 @@ def construct_type(*, value: object, type_: object, metadata: Optional[List[Any]
if not is_list(value):
return value

if not args:
return value

inner_type = args[0] # List[inner_type]
return [construct_type(value=entry, type_=inner_type) for entry in value]

Expand Down
4 changes: 4 additions & 0 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ class NestedModel(BaseModel):
assert cast(Any, m.nested) is False


def test_bare_list_type() -> None:
assert construct_type(value=[{"hello": "world"}], type_=list) == [{"hello": "world"}]


def test_raw_dictionary() -> None:
class NestedModel(BaseModel):
nested: Dict[str, str]
Expand Down