()
| 448 | |
| 449 | |
| 450 | def 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 | |
| 473 | def test_min_length_field_info_not_lost(): |
nothing calls this directly
no test coverage detected