()
| 1033 | |
| 1034 | @pytest.mark.skipif(PYDANTIC_V1, reason="this is only supported in pydantic v2 for now") |
| 1035 | def test_extra_properties() -> None: |
| 1036 | class Item(BaseModel): |
| 1037 | prop: int |
| 1038 | |
| 1039 | class Model(BaseModel): |
| 1040 | __pydantic_extra__: Dict[str, Item] = Field(init=False) # pyright: ignore[reportIncompatibleVariableOverride] |
| 1041 | |
| 1042 | other: str |
| 1043 | |
| 1044 | if TYPE_CHECKING: |
| 1045 | |
| 1046 | def __getattr__(self, attr: str) -> Item: ... |
| 1047 | |
| 1048 | model = construct_type( |
| 1049 | type_=Model, |
| 1050 | value={ |
| 1051 | "a": {"prop": 1}, |
| 1052 | "other": "foo", |
| 1053 | }, |
| 1054 | ) |
| 1055 | assert isinstance(model, Model) |
| 1056 | assert model.a.prop == 1 |
| 1057 | assert isinstance(model.a, Item) |
| 1058 | assert model.other == "foo" |
| 1059 | |
| 1060 | |
| 1061 | # NOTE: Workaround for Pydantic Iterable behavior. |
nothing calls this directly
no test coverage detected