test_discriminated_unions_invalid_data() — anthropic-sdk-python Function Reference
Architecture documentation for the test_discriminated_unions_invalid_data() function in test_models.py from the anthropic-sdk-python codebase.
Entity Profile
Dependency Diagram
graph TD ec8b52ba_9f8b_7820_8437_2c087a9e1b5c["test_discriminated_unions_invalid_data()"] 7872e60b_4210_5600_119f_c5d08c52091e["test_models.py"] ec8b52ba_9f8b_7820_8437_2c087a9e1b5c -->|defined in| 7872e60b_4210_5600_119f_c5d08c52091e style ec8b52ba_9f8b_7820_8437_2c087a9e1b5c fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
tests/test_models.py lines 657–687
def test_discriminated_unions_invalid_data() -> None:
class A(BaseModel):
type: Literal["a"]
data: str
class B(BaseModel):
type: Literal["b"]
data: int
m = construct_type(
value={"type": "b", "data": "foo"},
type_=cast(Any, Annotated[Union[A, B], PropertyInfo(discriminator="type")]),
)
assert isinstance(m, B)
assert m.type == "b"
assert m.data == "foo" # type: ignore[comparison-overlap]
m = construct_type(
value={"type": "a", "data": 100},
type_=cast(Any, Annotated[Union[A, B], PropertyInfo(discriminator="type")]),
)
assert isinstance(m, A)
assert m.type == "a"
if PYDANTIC_V1:
# pydantic v1 automatically converts inputs to strings
# if the expected type is a str
assert m.data == "100"
else:
assert m.data == 100 # type: ignore[comparison-overlap]
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does test_discriminated_unions_invalid_data() do?
test_discriminated_unions_invalid_data() is a function in the anthropic-sdk-python codebase, defined in tests/test_models.py.
Where is test_discriminated_unions_invalid_data() defined?
test_discriminated_unions_invalid_data() is defined in tests/test_models.py at line 657.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free