Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit a2c6da0

Browse files
stainless-app[bot]stainless-bot
authored andcommittedFeb 6, 2025·
chore(internal): minor type handling changes (#2099)
1 parent 1882483 commit a2c6da0

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed
 

‎src/openai/_models.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -451,10 +451,16 @@ def construct_type(*, value: object, type_: object) -> object:
451451
452452
If the given value does not match the expected type then it is returned as-is.
453453
"""
454+
455+
# store a reference to the original type we were given before we extract any inner
456+
# types so that we can properly resolve forward references in `TypeAliasType` annotations
457+
original_type = None
458+
454459
# we allow `object` as the input type because otherwise, passing things like
455460
# `Literal['value']` will be reported as a type error by type checkers
456461
type_ = cast("type[object]", type_)
457462
if is_type_alias_type(type_):
463+
original_type = type_ # type: ignore[unreachable]
458464
type_ = type_.__value__ # type: ignore[unreachable]
459465

460466
# unwrap `Annotated[T, ...]` -> `T`
@@ -471,7 +477,7 @@ def construct_type(*, value: object, type_: object) -> object:
471477

472478
if is_union(origin):
473479
try:
474-
return validate_type(type_=cast("type[object]", type_), value=value)
480+
return validate_type(type_=cast("type[object]", original_type or type_), value=value)
475481
except Exception:
476482
pass
477483

0 commit comments

Comments
 (0)
Please sign in to comment.