Home / Function/ test_nested_discriminated_union() — anthropic-sdk-python Function Reference

test_nested_discriminated_union() — anthropic-sdk-python Function Reference

Architecture documentation for the test_nested_discriminated_union() function in test_models.py from the anthropic-sdk-python codebase.

Entity Profile

Dependency Diagram

graph TD
  643e9145_643c_8152_7044_899607b47eb9["test_nested_discriminated_union()"]
  7872e60b_4210_5600_119f_c5d08c52091e["test_models.py"]
  643e9145_643c_8152_7044_899607b47eb9 -->|defined in| 7872e60b_4210_5600_119f_c5d08c52091e
  style 643e9145_643c_8152_7044_899607b47eb9 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

tests/test_models.py lines 894–936

def test_nested_discriminated_union() -> None:
    class InnerType1(BaseModel):
        type: Literal["type_1"]

    class InnerModel(BaseModel):
        inner_value: str

    class InnerType2(BaseModel):
        type: Literal["type_2"]
        some_inner_model: InnerModel

    class Type1(BaseModel):
        base_type: Literal["base_type_1"]
        value: Annotated[
            Union[
                InnerType1,
                InnerType2,
            ],
            PropertyInfo(discriminator="type"),
        ]

    class Type2(BaseModel):
        base_type: Literal["base_type_2"]

    T = Annotated[
        Union[
            Type1,
            Type2,
        ],
        PropertyInfo(discriminator="base_type"),
    ]

    model = construct_type(
        type_=T,
        value={
            "base_type": "base_type_1",
            "value": {
                "type": "type_2",
            },
        },
    )
    assert isinstance(model, Type1)
    assert isinstance(model.value, InnerType2)

Subdomains

Frequently Asked Questions

What does test_nested_discriminated_union() do?
test_nested_discriminated_union() is a function in the anthropic-sdk-python codebase, defined in tests/test_models.py.
Where is test_nested_discriminated_union() defined?
test_nested_discriminated_union() is defined in tests/test_models.py at line 894.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free