MCPcopy Create free account
hub / github.com/anthropics/anthropic-sdk-python / test_discriminated_union_case

Function test_discriminated_union_case

tests/test_models.py:957–986  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

955
956
957def test_discriminated_union_case() -> None:
958 class A(BaseModel):
959 type: Literal["a"]
960
961 data: bool
962
963 class B(BaseModel):
964 type: Literal["b"]
965
966 data: List[Union[A, object]]
967
968 class ModelA(BaseModel):
969 type: Literal["modelA"]
970
971 data: int
972
973 class ModelB(BaseModel):
974 type: Literal["modelB"]
975
976 required: str
977
978 data: Union[A, B]
979
980 # when constructing ModelA | ModelB, value data doesn't match ModelB exactly - missing `required`
981 m = construct_type(
982 value={"type": "modelB", "data": {"type": "a", "data": True}},
983 type_=cast(Any, Annotated[Union[ModelA, ModelB], UnionDiscriminator("type")]),
984 )
985
986 assert isinstance(m, ModelB)
987
988
989def test_nested_discriminated_union() -> None:

Callers

nothing calls this directly

Calls 2

construct_typeFunction · 0.90
UnionDiscriminatorClass · 0.90

Tested by

no test coverage detected