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

test_union_response_different_types() — anthropic-sdk-python Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  f951a627_c0e3_aade_df00_fae590a160e8["test_union_response_different_types()"]
  9bf4cfe0_e3b0_70de_25ac_2113c8918900["TestAsyncAnthropic"]
  f951a627_c0e3_aade_df00_fae590a160e8 -->|defined in| 9bf4cfe0_e3b0_70de_25ac_2113c8918900
  bf09941f_781e_17a7_4217_86c4231e9dda["test_union_response_different_types()"]
  bf09941f_781e_17a7_4217_86c4231e9dda -->|calls| f951a627_c0e3_aade_df00_fae590a160e8
  bf09941f_781e_17a7_4217_86c4231e9dda["test_union_response_different_types()"]
  f951a627_c0e3_aade_df00_fae590a160e8 -->|calls| bf09941f_781e_17a7_4217_86c4231e9dda
  style f951a627_c0e3_aade_df00_fae590a160e8 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

tests/test_client.py lines 1627–1646

    async def test_union_response_different_types(self, respx_mock: MockRouter, async_client: AsyncAnthropic) -> None:
        """Union of objects with the same field name using a different type"""

        class Model1(BaseModel):
            foo: int

        class Model2(BaseModel):
            foo: str

        respx_mock.get("/foo").mock(return_value=httpx.Response(200, json={"foo": "bar"}))

        response = await async_client.get("/foo", cast_to=cast(Any, Union[Model1, Model2]))
        assert isinstance(response, Model2)
        assert response.foo == "bar"

        respx_mock.get("/foo").mock(return_value=httpx.Response(200, json={"foo": 1}))

        response = await async_client.get("/foo", cast_to=cast(Any, Union[Model1, Model2]))
        assert isinstance(response, Model1)
        assert response.foo == 1

Subdomains

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free