()
| 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) |
| 937 | |
| 938 | |
| 939 | @pytest.mark.skipif(not PYDANTIC_V2, reason="this is only supported in pydantic v2 for now") |
nothing calls this directly
no test coverage detected