Skip to content

Commit d72f39f

Browse files
feat(api): api update
1 parent 12de9f3 commit d72f39f

File tree

2 files changed

+5
-53
lines changed

2 files changed

+5
-53
lines changed

src/browserbase/_models.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22

33
import os
44
import inspect
5-
from typing import TYPE_CHECKING, Any, Type, Union, Generic, TypeVar, Callable, Optional, cast
5+
from typing import TYPE_CHECKING, Any, Type, Union, Generic, TypeVar, Callable, cast
66
from datetime import date, datetime
77
from typing_extensions import (
8-
List,
98
Unpack,
109
Literal,
1110
ClassVar,
@@ -367,7 +366,7 @@ def _construct_field(value: object, field: FieldInfo, key: str) -> object:
367366
if type_ is None:
368367
raise RuntimeError(f"Unexpected field type is None for {key}")
369368

370-
return construct_type(value=value, type_=type_, metadata=getattr(field, "metadata", None))
369+
return construct_type(value=value, type_=type_)
371370

372371

373372
def is_basemodel(type_: type) -> bool:
@@ -421,7 +420,7 @@ def construct_type_unchecked(*, value: object, type_: type[_T]) -> _T:
421420
return cast(_T, construct_type(value=value, type_=type_))
422421

423422

424-
def construct_type(*, value: object, type_: object, metadata: Optional[List[Any]] = None) -> object:
423+
def construct_type(*, value: object, type_: object) -> object:
425424
"""Loose coercion to the expected type with construction of nested values.
426425
427426
If the given value does not match the expected type then it is returned as-is.
@@ -439,10 +438,8 @@ def construct_type(*, value: object, type_: object, metadata: Optional[List[Any]
439438
type_ = type_.__value__ # type: ignore[unreachable]
440439

441440
# unwrap `Annotated[T, ...]` -> `T`
442-
if metadata is not None:
443-
meta: tuple[Any, ...] = tuple(metadata)
444-
elif is_annotated_type(type_):
445-
meta = get_args(type_)[1:]
441+
if is_annotated_type(type_):
442+
meta: tuple[Any, ...] = get_args(type_)[1:]
446443
type_ = extract_type_arg(type_, 0)
447444
else:
448445
meta = tuple()

tests/test_models.py

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -889,48 +889,3 @@ class ModelB(BaseModel):
889889
)
890890

891891
assert isinstance(m, ModelB)
892-
893-
894-
def test_nested_discriminated_union() -> None:
895-
class InnerType1(BaseModel):
896-
type: Literal["type_1"]
897-
898-
class InnerModel(BaseModel):
899-
inner_value: str
900-
901-
class InnerType2(BaseModel):
902-
type: Literal["type_2"]
903-
some_inner_model: InnerModel
904-
905-
class Type1(BaseModel):
906-
base_type: Literal["base_type_1"]
907-
value: Annotated[
908-
Union[
909-
InnerType1,
910-
InnerType2,
911-
],
912-
PropertyInfo(discriminator="type"),
913-
]
914-
915-
class Type2(BaseModel):
916-
base_type: Literal["base_type_2"]
917-
918-
T = Annotated[
919-
Union[
920-
Type1,
921-
Type2,
922-
],
923-
PropertyInfo(discriminator="base_type"),
924-
]
925-
926-
model = construct_type(
927-
type_=T,
928-
value={
929-
"base_type": "base_type_1",
930-
"value": {
931-
"type": "type_2",
932-
},
933-
},
934-
)
935-
assert isinstance(model, Type1)
936-
assert isinstance(model.value, InnerType2)

0 commit comments

Comments
 (0)