Skip to content

fix: handle bare dict annotations in construct_type#3379

Open
Muhtasim-Munif-Fahim wants to merge 3 commits into
openai:mainfrom
Muhtasim-Munif-Fahim:codex/python-3341-bare-dict-construct-type
Open

fix: handle bare dict annotations in construct_type#3379
Muhtasim-Munif-Fahim wants to merge 3 commits into
openai:mainfrom
Muhtasim-Munif-Fahim:codex/python-3341-bare-dict-construct-type

Conversation

@Muhtasim-Munif-Fahim

Copy link
Copy Markdown

Fix construct_type() so a bare dict annotation does not crash when the code path inspects get_args(type_).

This keeps the deserialization path aligned with the transform utility and preserves the input value unchanged when there are no dict type arguments.

Tests:

  • python -m pytest tests/test_models.py -k "bare_dict_annotation or extra_properties" -q
  • python -m py_compile src/openai/_models.py tests/test_models.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

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.

Pull request overview

Note

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

This PR improves model/type handling and schema parity by ensuring realtime error payloads include a human-readable message, and by making construct_type() safely handle bare dict annotations.

Changes:

  • Add message field to RealtimeResponseStatus.Error (beta and non-beta).
  • Update construct_type() to tolerate type_=dict (no generic args) without throwing.
  • Add tests for bare dict annotation and for realtime error message parsing.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/test_models.py Adds regression test for construct_type(..., type_=dict) behavior
tests/lib/test_realtime_response_status.py Adds test asserting realtime status error payload includes message in both beta and stable types
src/openai/types/realtime/realtime_response_status.py Adds Error.message field to realtime status model
src/openai/types/beta/realtime/realtime_response_status.py Adds Error.message field to beta realtime status model
src/openai/_models.py Fixes construct_type() dict handling when dict is not subscripted

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

Comment thread src/openai/_models.py
Comment on lines +660 to 664
args = get_args(type_)
if len(args) < 2:
return value
items_type = args[1]
return {key: construct_type(value=item, type_=items_type) for key, item in value.items()}

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: aa64636434

ℹ️ 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.

P1 Badge Use a Pydantic-v1-compatible model constructor

The repository supports Pydantic 1.x, and the test-pydantic-v1 nox session runs this test without excluding it, but Pydantic v1's BaseModel has no model_validate method and the SDK does not provide that shim. This therefore raises AttributeError for both parametrized cases in the compatibility suite; construct the models through a version-compatible helper such as parse_obj instead.

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