Skip to content

fix: handle bare dict annotations in construct_type#3386

Open
Resurgamz wants to merge 1 commit into
openai:mainfrom
Resurgamz:fix/issue-3341-bare-dict-construct-type
Open

fix: handle bare dict annotations in construct_type#3386
Resurgamz wants to merge 1 commit into
openai:mainfrom
Resurgamz:fix/issue-3341-bare-dict-construct-type

Conversation

@Resurgamz

Copy link
Copy Markdown

Summary

  • Return bare dict values unchanged during model construction when no value type argument is available.
  • Add a regression test for BaseModel.construct() with a field annotated as plain dict.

Changes

File Change
src/openai/_models.py Guard dict value type unpacking when get_args(dict) is empty.
tests/test_models.py Cover model construction for bare dict fields.

Test Plan

  • PYTHONPATH="$PWD/src" /home/ut006460@uos/project/openai-python/.venv/bin/python -m pytest tests/test_models.py -k bare_dictionary -n 0
  • PYTHONPATH="$PWD/src" /home/ut006460@uos/project/openai-python/.venv/bin/python -m pytest tests/test_models.py -n 0
  • /home/ut006460@uos/project/openai-python/.venv/bin/ruff format tests/test_models.py src/openai/_models.py
  • /home/ut006460@uos/project/openai-python/.venv/bin/ruff check tests/test_models.py src/openai/_models.py

Fixes #3341

Avoid unpacking missing type arguments when model construction sees an unparameterized dict field.

Fixes openai#3341
@Resurgamz Resurgamz marked this pull request as ready for review June 9, 2026 01:43
@Resurgamz Resurgamz requested a review from a team as a code owner June 9, 2026 01:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: construct_type() crashes with ValueError on bare dict annotation (no type args)

1 participant