test_discriminated_unions_invalid_data_uses_cache() — anthropic-sdk-python Function Reference
Architecture documentation for the test_discriminated_unions_invalid_data_uses_cache() function in test_models.py from the anthropic-sdk-python codebase.
Entity Profile
Dependency Diagram
graph TD f47f4c88_4777_5966_99d9_afdc0d7080f9["test_discriminated_unions_invalid_data_uses_cache()"] 7872e60b_4210_5600_119f_c5d08c52091e["test_models.py"] f47f4c88_4777_5966_99d9_afdc0d7080f9 -->|defined in| 7872e60b_4210_5600_119f_c5d08c52091e style f47f4c88_4777_5966_99d9_afdc0d7080f9 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
tests/test_models.py lines 799–833
def test_discriminated_unions_invalid_data_uses_cache() -> None:
class A(BaseModel):
type: Literal["a"]
data: str
class B(BaseModel):
type: Literal["b"]
data: int
UnionType = cast(Any, Union[A, B])
assert not DISCRIMINATOR_CACHE.get(UnionType)
m = construct_type(
value={"type": "b", "data": "foo"}, type_=cast(Any, Annotated[UnionType, PropertyInfo(discriminator="type")])
)
assert isinstance(m, B)
assert m.type == "b"
assert m.data == "foo" # type: ignore[comparison-overlap]
discriminator = DISCRIMINATOR_CACHE.get(UnionType)
assert discriminator is not None
m = construct_type(
value={"type": "b", "data": "foo"}, type_=cast(Any, Annotated[UnionType, PropertyInfo(discriminator="type")])
)
assert isinstance(m, B)
assert m.type == "b"
assert m.data == "foo" # type: ignore[comparison-overlap]
# if the discriminator details object stays the same between invocations then
# we hit the cache
assert DISCRIMINATOR_CACHE.get(UnionType) is discriminator
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does test_discriminated_unions_invalid_data_uses_cache() do?
test_discriminated_unions_invalid_data_uses_cache() is a function in the anthropic-sdk-python codebase, defined in tests/test_models.py.
Where is test_discriminated_unions_invalid_data_uses_cache() defined?
test_discriminated_unions_invalid_data_uses_cache() is defined in tests/test_models.py at line 799.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free