Skip to content

fix: handle bare dict annotations in transform#3380

Open
Muhtasim-Munif-Fahim wants to merge 3 commits into
openai:mainfrom
Muhtasim-Munif-Fahim:codex/python-3338-bare-dict-transform
Open

fix: handle bare dict annotations in transform#3380
Muhtasim-Munif-Fahim wants to merge 3 commits into
openai:mainfrom
Muhtasim-Munif-Fahim:codex/python-3338-bare-dict-transform

Conversation

@Muhtasim-Munif-Fahim
Copy link
Copy Markdown

Fix _transform_recursive() so bare dict annotations do not crash when the code path inspects get_args(stripped_type)[1].

This keeps both sync and async transform paths aligned and preserves the original mapping when the dict annotation has no type arguments.

Tests:

  • python -m pytest tests/test_transform.py -k bare_dict_annotation -q
  • python -m pytest tests/test_transform.py -k "bare_dict_annotation or dictionary_items" -q
  • python -m py_compile src/openai/_utils/_transform.py tests/test_transform.py

Copilot AI review requested due to automatic review settings June 8, 2026 01:30
@Muhtasim-Munif-Fahim Muhtasim-Munif-Fahim requested a review from a team as a code owner June 8, 2026 01:30
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR improves type transformation and realtime error typing by handling “bare” dict annotations during request transformation and exposing an error message field on realtime status models.

Changes:

  • Handle dict annotations without type arguments in _transform_recursive/_async_transform_recursive (avoid get_args(...)[1] failures).
  • Add message to RealtimeResponseStatus.Error (beta and non-beta) and validate via a new test.
  • Add a regression test to ensure TypedDict fields annotated as bare dict are preserved.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tests/test_transform.py Adds coverage for transforming a TypedDict containing a bare dict field.
tests/lib/test_realtime_response_status.py Adds test ensuring realtime status error payload includes message.
src/openai/types/realtime/realtime_response_status.py Adds Error.message to the non-beta realtime status type.
src/openai/types/beta/realtime/realtime_response_status.py Adds Error.message to the beta realtime status type.
src/openai/_utils/_transform.py Avoids indexing missing type args for bare dict annotations (sync/async paths).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +352 to 356
args = get_args(stripped_type)
if len(args) < 2:
return data
items_type = args[1]
return {key: _transform_recursive(value, annotation=items_type) for key, value in data.items()}
Comment on lines +183 to +185
args = get_args(stripped_type)
if len(args) < 2:
return data
import pytest

from openai.types.beta.realtime import RealtimeResponseStatus as BetaRealtimeResponseStatus
from openai.types.realtime import RealtimeResponseStatus as RealtimeResponseStatus
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 136d4ec6b4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

ids=["beta", "realtime"],
)
def test_realtime_response_status_error_message(status_cls: type[BaseModel]) -> None:
status = status_cls.model_validate(
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Use pydantic-compatible parsing in the new test

In the test-pydantic-v1 nox session, noxfile.py installs pydantic<2 and runs the test suite, but these generated models inherit from openai._models.BaseModel, which does not provide model_validate under Pydantic v1. This new test will raise AttributeError before reaching the assertions in that CI context; use the repository compatibility helper such as openai._compat.parse_obj/model_parse, or another v1-compatible construction path.

Useful? React with 👍 / 👎.

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.

3 participants