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

test_nested_union_invalid_data() — anthropic-sdk-python Function Reference

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

Entity Profile

Dependency Diagram

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

Relationship Graph

Source Code

tests/test_models.py lines 283–302

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

    class Submodel2(BaseModel):
        name: str

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

    m = Model.construct(foo=True)
    assert cast(bool, m.foo) is True

    m = Model.construct(foo={"name": 3})
    if PYDANTIC_V1:
        assert isinstance(m.foo, Submodel2)
        assert m.foo.name == "3"
    else:
        assert isinstance(m.foo, Submodel1)
        assert m.foo.name == 3  # type: ignore

Subdomains

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free