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

test_optional_list_nested_model() — anthropic-sdk-python Function Reference

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

Entity Profile

Dependency Diagram

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

Relationship Graph

Source Code

tests/test_models.py lines 73–92

def test_optional_list_nested_model() -> None:
    class NestedModel(BaseModel):
        nested: Optional[List[BasicModel]]

    m1 = NestedModel.construct(nested=[{"foo": "bar"}, {"foo": "2"}])
    assert m1.nested is not None
    assert isinstance(m1.nested, list)
    assert len(m1.nested) == 2
    assert m1.nested[0].foo == "bar"
    assert m1.nested[1].foo == "2"

    m2 = NestedModel.construct(nested=None)
    assert m2.nested is None

    # mismatched types
    m3 = NestedModel.construct(nested={1})
    assert cast(Any, m3.nested) == {1}

    m4 = NestedModel.construct(nested=[False])
    assert cast(Any, m4.nested) == [False]

Subdomains

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free