MCPcopy
hub / github.com/pydantic/pydantic / test_annotated_private_field_with_default

Function test_annotated_private_field_with_default

tests/test_annotated.py:450–470  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

448
449
450def test_annotated_private_field_with_default():
451 class AnnotatedPrivateFieldModel(BaseModel):
452 _foo: Annotated[int, PrivateAttr(default=1)]
453 _bar: Annotated[str, 'hello']
454 _baz: 'Annotated[str, PrivateAttr(default=2)]'
455
456 model = AnnotatedPrivateFieldModel()
457 assert model._foo == 1
458 assert model._baz == 2
459
460 assert model.__pydantic_private__ == {'_foo': 1, '_baz': 2}
461
462 with pytest.raises(AttributeError):
463 assert model._bar
464
465 model._bar = 'world'
466 assert model._bar == 'world'
467 assert model.__pydantic_private__ == {'_foo': 1, '_bar': 'world', '_baz': 2}
468
469 with pytest.raises(AttributeError):
470 assert model.bar
471
472
473def test_min_length_field_info_not_lost():

Callers

nothing calls this directly

Calls 1

Tested by

no test coverage detected