Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/openai/_utils/_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,10 @@ def _transform_recursive(
return _transform_typeddict(data, stripped_type)

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

if (
Expand Down Expand Up @@ -346,7 +349,10 @@ async def _async_transform_recursive(
return await _async_transform_typeddict(data, stripped_type)

if origin == dict and is_mapping(data):
items_type = get_args(stripped_type)[1]
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 +352 to 356

if (
Expand Down
3 changes: 3 additions & 0 deletions src/openai/types/beta/realtime/realtime_response_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ class Error(BaseModel):
code: Optional[str] = None
"""Error code, if any."""

message: Optional[str] = None
"""A human-readable description of the error, if any."""

type: Optional[str] = None
"""The type of error."""

Expand Down
3 changes: 3 additions & 0 deletions src/openai/types/realtime/realtime_response_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ class Error(BaseModel):
code: Optional[str] = None
"""Error code, if any."""

message: Optional[str] = None
"""A human-readable description of the error, if any."""

type: Optional[str] = None
"""The type of error."""

Expand Down
31 changes: 31 additions & 0 deletions tests/lib/test_realtime_response_status.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from __future__ import annotations

from pydantic import BaseModel
import pytest

from openai.types.beta.realtime import RealtimeResponseStatus as BetaRealtimeResponseStatus
from openai.types.realtime import RealtimeResponseStatus as RealtimeResponseStatus


@pytest.mark.parametrize(
"status_cls",
[BetaRealtimeResponseStatus, RealtimeResponseStatus],
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 👍 / 👎.

{
"error": {
"code": "bad_request",
"message": "The model could not process the request.",
"type": "invalid_request_error",
},
"type": "failed",
}
)

assert status.error is not None
assert status.error.code == "bad_request"
assert status.error.message == "The model could not process the request."
assert status.error.type == "invalid_request_error"
assert status.type == "failed"
12 changes: 12 additions & 0 deletions tests/test_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,18 @@ class DictItems(TypedDict):
assert await transform({"foo": {"foo_baz": "bar"}}, Dict[str, DictItems], use_async) == {"foo": {"fooBaz": "bar"}}


class BareDictItems(TypedDict):
metadata: dict # pyright: ignore[reportMissingTypeArgument]


@parametrize
@pytest.mark.asyncio
async def test_bare_dict_annotation(use_async: bool) -> None:
assert await transform({"metadata": {"key": "value"}}, BareDictItems, use_async) == {
"metadata": {"key": "value"}
}


class TypedDictIterableUnionStr(TypedDict):
foo: Annotated[Union[str, Iterable[Baz8]], PropertyInfo(alias="FOO")]

Expand Down