MCPcopy Create free account
hub / github.com/anthropics/anthropic-sdk-python / test_nested_union_invalid_data

Function test_nested_union_invalid_data

tests/test_models.py:283–302  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

281
282
283def test_nested_union_invalid_data() -> None:
284 class Submodel1(BaseModel):
285 level: int
286
287 class Submodel2(BaseModel):
288 name: str
289
290 class Model(BaseModel):
291 foo: Union[Submodel1, Submodel2]
292
293 m = Model.construct(foo=True)
294 assert cast(bool, m.foo) is True
295
296 m = Model.construct(foo={"name": 3})
297 if PYDANTIC_V2:
298 assert isinstance(m.foo, Submodel1)
299 assert m.foo.name == 3 # type: ignore
300 else:
301 assert isinstance(m.foo, Submodel2)
302 assert m.foo.name == "3"
303
304
305def test_list_of_unions() -> None:

Callers

nothing calls this directly

Calls 1

constructMethod · 0.45

Tested by

no test coverage detected