fix: handle bare dict annotation in construct_type()#3347
Open
gavin913-lss wants to merge 1 commit into
Open
Conversation
When type_ is a bare dict without type parameters (e.g. dict instead of dict[str, Any]), get_args(dict) returns an empty tuple. The previous code unconditionally unpacked two values from it, causing ValueError. Add a length check before unpacking and return the value as-is for bare dicts since there are no type parameters to recurse into. Fixes openai#3341
nomiveritas
approved these changes
Jun 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What breaks
construct_type()insrc/openai/_models.pycrashes withValueErrorwhentype_is a bare, unparameteriseddict(no[K, V]type arguments).Fixes #3341
Root cause
Line 660 does
_, items_type = get_args(type_)after checkingorigin == dict. For baredict,get_args(dict)returns an empty tuple(), and unpacking with two targets raisesValueError.Fix
Add a length check before unpacking. When
get_args()returns fewer than 2 elements (baredict), return the value as-is since there are no type parameters to recurse into.Tests
Added
test_bare_dict_annotation()covering:dictwith string valuesdictwith int valuesdictAll existing
test_models.pytests continue to pass.