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

test_nested_union_multiple_variants() — anthropic-sdk-python Function Reference

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

Entity Profile

Dependency Diagram

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

Relationship Graph

Source Code

tests/test_models.py lines 255–280

def test_nested_union_multiple_variants() -> None:
    class Submodel1(BaseModel):
        bar: bool

    class Submodel2(BaseModel):
        thing: str

    class Submodel3(BaseModel):
        foo: int

    class Model(BaseModel):
        foo: Union[Submodel1, Submodel2, None, Submodel3]

    m = Model.construct(foo={"thing": "hello"})
    assert isinstance(m.foo, Submodel2)
    assert m.foo.thing == "hello"

    m = Model.construct(foo=None)
    assert m.foo is None

    m = Model.construct()
    assert m.foo is None

    m = Model.construct(foo={"foo": "1"})
    assert isinstance(m.foo, Submodel3)
    assert m.foo.foo == 1

Subdomains

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free