Skip to content

fix(models): handle bare dict/list type annotations without type parameters - #3360

Closed
tianming-1996 wants to merge 2 commits into
openai:mainfrom
tianming-1996:fix/issue-3338-3341-bare-dict
Closed

fix(models): handle bare dict/list type annotations without type parameters#3360
tianming-1996 wants to merge 2 commits into
openai:mainfrom
tianming-1996:fix/issue-3338-3341-bare-dict

Conversation

@tianming-1996

@tianming-1996 tianming-1996 commented Jun 4, 2026

Copy link
Copy Markdown

Summary

  • Fixed IndexError in _transform_recursive when TypedDict fields use bare dict annotations (e.g. metadata: dict instead of metadata: dict[str, str])
  • Fixed ValueError in construct_type() when deserializing bare dict annotations
  • Fixed RuntimeError from extract_type_arg() for bare list annotations in transform
  • Fixed the same issues in async counterparts (_async_transform_recursive)

Changes

File Change
src/openai/_utils/_transform.py Add get_args() length check in dict branch; handle bare list in list/iterable/sequence branches (sync + async)
src/openai/_models.py Add get_args() length check in dict branch; handle bare list in list branch
tests/test_transform.py Add 3 regression tests for bare dict/list annotations (sync + async)
tests/test_models.py Add 4 regression tests for construct_type() with bare dict/list

Root Cause

All four bugs share the same root cause: when a type like dict or list is used without generic parameters, typing.get_args() returns an empty tuple (). Code that unconditionally indexed into this tuple (e.g. get_args(type_)[1]) or unpacked it (e.g. _, items_type = get_args(type_)) would crash.

Test Plan

  • All 10 new regression tests pass (sync + async)
  • All 124 existing tests in test_transform.py and test_models.py pass
  • CI checks pass

Fixes #3338
Fixes #3341

…meters

When a TypedDict field is annotated with bare 'dict' or 'list' (without
type parameters like dict[str, str] or list[int]), calling transform() or
construct_type() would crash with IndexError or ValueError.

Fixes openai#3338: IndexError in _transform_recursive when TypedDict field uses
bare dict annotation
Fixes openai#3341: construct_type() crashes with ValueError on bare dict annotation
Also fixes: bare list annotation causing extract_type_arg() to fail

Changes:
- _transform.py: Add args length check in dict branch, handle bare list in
  list/iterable/sequence branches for both sync and async versions
- _models.py: Add args length check in dict branch, handle bare list in
  list branch
- Add regression tests for bare dict and bare list annotations

Signed-off-by: tianming-1996 <tianming@example.com>
@tianming-1996
tianming-1996 marked this pull request as ready for review June 4, 2026 03:39
@tianming-1996
tianming-1996 requested a review from a team as a code owner June 4, 2026 03:39
@tianming-1996

Copy link
Copy Markdown
Author

Hi @apcha-oai @jbeckwith-oai, could you please take a look at this PR? It fixes IndexError/ValueError/RuntimeError when using bare dict/list type annotations (e.g. metadata: dict instead of metadata: dict[str, str]) in the SDK. One community review is already approved. This resolves #3338 and #3341. Thanks!

Copy link
Copy Markdown
Contributor

Thank you for the contribution. The missing type arguments for bare dict and list annotations are now handled in model construction and sync/async request transformation by #3760, which is merged into main.

Closing this PR because the merged change resolves the same crash. Please use a release containing #3760 when available; the fix is not included in v3.11.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants