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

Function test_discriminated_union_case

tests/test_models.py:976–1005  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

974
975
976def test_discriminated_union_case() -> None:
977 class A(BaseModel):
978 type: Literal["a"]
979
980 data: bool
981
982 class B(BaseModel):
983 type: Literal["b"]
984
985 data: List[Union[A, object]]
986
987 class ModelA(BaseModel):
988 type: Literal["modelA"]
989
990 data: int
991
992 class ModelB(BaseModel):
993 type: Literal["modelB"]
994
995 required: str
996
997 data: Union[A, B]
998
999 # when constructing ModelA | ModelB, value data doesn't match ModelB exactly - missing `required`
1000 m = construct_type(
1001 value={"type": "modelB", "data": {"type": "a", "data": True}},
1002 type_=cast(Any, Annotated[Union[ModelA, ModelB], UnionDiscriminator("type")]),
1003 )
1004
1005 assert isinstance(m, ModelB)
1006
1007
1008def 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