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
6 changes: 5 additions & 1 deletion src/openai/_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,11 @@ 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_)
if not args:
# bare `dict` with no type arguments — return value as-is
return value
_, items_type = args # Dict[_, items_type]
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 @@ -655,6 +655,12 @@ class Model(BaseModel):
assert m.value == "foo"


def test_construct_type_bare_dict_annotation() -> None:
# bare `dict` (no type args) must not raise ValueError on unpack
result = construct_type(value={"key": "value"}, type_=dict)
assert result == {"key": "value"}


def test_discriminated_unions_invalid_data() -> None:
class A(BaseModel):
type: Literal["a"]
Expand Down