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

test_list_of_unions() — anthropic-sdk-python Function Reference

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

Entity Profile

Dependency Diagram

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

Relationship Graph

Source Code

tests/test_models.py lines 305–326

def test_list_of_unions() -> None:
    class Submodel1(BaseModel):
        level: int

    class Submodel2(BaseModel):
        name: str

    class Model(BaseModel):
        items: List[Union[Submodel1, Submodel2]]

    m = Model.construct(items=[{"level": 1}, {"name": "Robert"}])
    assert len(m.items) == 2
    assert isinstance(m.items[0], Submodel1)
    assert m.items[0].level == 1
    assert isinstance(m.items[1], Submodel2)
    assert m.items[1].name == "Robert"

    m = Model.construct(items=[{"level": -1}, 156])
    assert len(m.items) == 2
    assert isinstance(m.items[0], Submodel1)
    assert m.items[0].level == -1
    assert cast(Any, m.items[1]) == 156

Subdomains

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free