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

test_double_nested_union() — anthropic-sdk-python Function Reference

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

Entity Profile

Dependency Diagram

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

Relationship Graph

Source Code

tests/test_models.py lines 381–402

def test_double_nested_union() -> None:
    class SubModel1(BaseModel):
        name: str

    class SubModel2(BaseModel):
        bar: str

    class Model(BaseModel):
        data: Dict[str, List[Union[SubModel1, SubModel2]]]

    m = Model.construct(data={"foo": [{"bar": "baz"}, {"name": "Robert"}]})
    assert len(m.data["foo"]) == 2

    entry1 = m.data["foo"][0]
    assert isinstance(entry1, SubModel2)
    assert entry1.bar == "baz"

    entry2 = m.data["foo"][1]
    assert isinstance(entry2, SubModel1)
    assert entry2.name == "Robert"

    # TODO: test mismatched type

Subdomains

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free