From 9edb32ae01aab84386130e2c489bcef1a3e6c8bf Mon Sep 17 00:00:00 2001 From: nightcityblade Date: Tue, 30 Jun 2026 23:16:37 +0800 Subject: [PATCH] fix: handle bare dict in construct_type --- src/openai/_models.py | 3 ++- tests/test_models.py | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/openai/_models.py b/src/openai/_models.py index 5cca20c6f9..d249abfc0a 100644 --- a/src/openai/_models.py +++ b/src/openai/_models.py @@ -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 ( diff --git a/tests/test_models.py b/tests/test_models.py index 588869ee35..e0191f4739 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_dict() -> None: + value = {"key": "value"} + + assert construct_type(value=value, type_=dict) == value