Skip to content

fix: handle bare dict annotation in construct_type and _transform_recursive - #3625

Open
Xsidz wants to merge 1 commit into
openai:mainfrom
Xsidz:fix/bare-dict-annotation-crash
Open

fix: handle bare dict annotation in construct_type and _transform_recursive#3625
Xsidz wants to merge 1 commit into
openai:mainfrom
Xsidz:fix/bare-dict-annotation-crash

Conversation

@Xsidz

@Xsidz Xsidz commented Aug 16, 2026

Copy link
Copy Markdown

Summary

Fixes #3341 and #3338.

construct_type() in _models.py and _transform_recursive() / _async_transform_recursive() in _utils/_transform.py all crashed when a field was annotated with a bare, unparameterised dict (no [K, V] type arguments):

  • _models.py:660: _, items_type = get_args(type_)get_args(dict) returns (), so the unpack raises ValueError: not enough values to unpack (expected 2, got 0).
  • _transform.py:183 and _transform.py:349: get_args(stripped_type)[1] — same empty tuple, raises IndexError.

The fix guards each site with a length check and falls back to Any when the dict is unparameterised, which preserves the existing value pass-through behaviour.

Test plan

…ursive

Fixes openai#3341 and openai#3338: when a field is annotated with plain `dict` (no
type parameters), `get_args(dict)` returns `()`. The old code unpacked
it with `_, items_type = get_args(type_)` / `get_args(stripped_type)[1]`,
raising ValueError / IndexError. Guard with a length check and fall back
to `Any` for unparameterised dicts.
@Xsidz
Xsidz requested a review from a team as a code owner August 16, 2026 16:43
Copilot AI lite review requested due to automatic review settings August 16, 2026 16:43

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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)

2 participants