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

assert_matches_model() — anthropic-sdk-python Function Reference

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

Function python AnthropicClient AsyncAPI calls 1 called by 1

Entity Profile

Dependency Diagram

graph TD
  d6d45846_cf41_8bdd_db9a_36feb297c8da["assert_matches_model()"]
  cf46c35e_ae7e_a652_f32b_5dd703f4d658["utils.py"]
  d6d45846_cf41_8bdd_db9a_36feb297c8da -->|defined in| cf46c35e_ae7e_a652_f32b_5dd703f4d658
  08e9c9e7_d7f9_615f_5837_b3de69122e37["assert_matches_type()"]
  08e9c9e7_d7f9_615f_5837_b3de69122e37 -->|calls| d6d45846_cf41_8bdd_db9a_36feb297c8da
  08e9c9e7_d7f9_615f_5837_b3de69122e37["assert_matches_type()"]
  d6d45846_cf41_8bdd_db9a_36feb297c8da -->|calls| 08e9c9e7_d7f9_615f_5837_b3de69122e37
  style d6d45846_cf41_8bdd_db9a_36feb297c8da fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

tests/utils.py lines 28–45

def assert_matches_model(model: type[BaseModelT], value: BaseModelT, *, path: list[str]) -> bool:
    for name, field in get_model_fields(model).items():
        field_value = getattr(value, name)
        if PYDANTIC_V1:
            # in v1 nullability was structured differently
            # https://docs.pydantic.dev/2.0/migration/#required-optional-and-nullable-fields
            allow_none = getattr(field, "allow_none", False)
        else:
            allow_none = False

        assert_matches_type(
            field_outer_type(field),
            field_value,
            path=[*path, name],
            allow_none=allow_none,
        )

    return True

Subdomains

Defined In

Frequently Asked Questions

What does assert_matches_model() do?
assert_matches_model() is a function in the anthropic-sdk-python codebase, defined in tests/utils.py.
Where is assert_matches_model() defined?
assert_matches_model() is defined in tests/utils.py at line 28.
What does assert_matches_model() call?
assert_matches_model() calls 1 function(s): assert_matches_type.
What calls assert_matches_model()?
assert_matches_model() is called by 1 function(s): assert_matches_type.

Analyze Your Own Codebase

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

Try Supermodel Free