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:298–317  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

296
297
298def test_nested_union_invalid_data() -> None:
299 class Submodel1(BaseModel):
300 level: int
301
302 class Submodel2(BaseModel):
303 name: str
304
305 class Model(BaseModel):
306 foo: Union[Submodel1, Submodel2]
307
308 m = Model.construct(foo=True)
309 assert cast(bool, m.foo) is True
310
311 m = Model.construct(foo={"name": 3})
312 if PYDANTIC_V1:
313 assert isinstance(m.foo, Submodel2)
314 assert m.foo.name == "3"
315 else:
316 assert isinstance(m.foo, Submodel1)
317 assert m.foo.name == 3 # type: ignore
318
319
320def test_list_of_unions() -> None:

Callers

nothing calls this directly

Calls 1

constructMethod · 0.45

Tested by

no test coverage detected