Skip to content
Open
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
4 changes: 2 additions & 2 deletions src/openai/_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import os
import inspect
from typing import TYPE_CHECKING, Any, Type, Tuple, Union, Generic, TypeVar, Callable, Optional, cast
from typing import TYPE_CHECKING, Any, Annotated, Type, Tuple, Union, Generic, TypeVar, Callable, Optional, cast
from datetime import date, datetime
from typing_extensions import (
List,
Expand Down Expand Up @@ -694,7 +694,7 @@ def _build_discriminated_union_meta(*, union: type, meta_annotations: tuple[Any,
discriminator_field=discriminator_field_name,
discriminator_alias=discriminator_alias,
)
cast(CachedDiscriminatorType, union).__discriminator__ = details
cast(CachedDiscriminatorType, Annotated[union, details])
Comment on lines 694 to +697

Choose a reason for hiding this comment

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

P1 Badge Restore caching of union discriminator metadata

The new code replaces cast(CachedDiscriminatorType, union).__discriminator__ = details with a bare cast(CachedDiscriminatorType, Annotated[union, details]). This only constructs an Annotated type and discards it, so the union instance never receives a __discriminator__ attribute. Subsequent calls to _build_discriminated_union_meta will therefore never hit the isinstance(union, CachedDiscriminatorType) fast path and tests that expect UnionType.__discriminator__ to exist (e.g. tests/test_models.py::test_discriminated_unions_invalid_data_uses_cache) will fail. Either the attribute assignment needs to be restored or the rest of the code must be updated to read metadata from the Annotated type instead.

Useful? React with 👍 / 👎.

return details


Expand Down