MCPcopy Create free account
hub / github.com/anomalyco/opencode-sdk-python / test_discriminated_union_case

Function test_discriminated_union_case

tests/test_models.py:862–891  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

860
861
862def test_discriminated_union_case() -> None:
863 class A(BaseModel):
864 type: Literal["a"]
865
866 data: bool
867
868 class B(BaseModel):
869 type: Literal["b"]
870
871 data: List[Union[A, object]]
872
873 class ModelA(BaseModel):
874 type: Literal["modelA"]
875
876 data: int
877
878 class ModelB(BaseModel):
879 type: Literal["modelB"]
880
881 required: str
882
883 data: Union[A, B]
884
885 # when constructing ModelA | ModelB, value data doesn't match ModelB exactly - missing `required`
886 m = construct_type(
887 value={"type": "modelB", "data": {"type": "a", "data": True}},
888 type_=cast(Any, Annotated[Union[ModelA, ModelB], PropertyInfo(discriminator="type")]),
889 )
890
891 assert isinstance(m, ModelB)
892
893
894def test_nested_discriminated_union() -> None:

Callers

nothing calls this directly

Calls 2

construct_typeFunction · 0.90
PropertyInfoClass · 0.90

Tested by

no test coverage detected