()
| 1052 | |
| 1053 | @pytest.mark.skipif(PYDANTIC_V1, reason="this is only supported in pydantic v2 for now") |
| 1054 | def test_extra_properties() -> None: |
| 1055 | class Item(BaseModel): |
| 1056 | prop: int |
| 1057 | |
| 1058 | class Model(BaseModel): |
| 1059 | __pydantic_extra__: Dict[str, Item] = Field(init=False) # pyright: ignore[reportIncompatibleVariableOverride] |
| 1060 | |
| 1061 | other: str |
| 1062 | |
| 1063 | if TYPE_CHECKING: |
| 1064 | |
| 1065 | def __getattr__(self, attr: str) -> Item: ... |
| 1066 | |
| 1067 | model = construct_type( |
| 1068 | type_=Model, |
| 1069 | value={ |
| 1070 | "a": {"prop": 1}, |
| 1071 | "other": "foo", |
| 1072 | }, |
| 1073 | ) |
| 1074 | assert isinstance(model, Model) |
| 1075 | assert model.a.prop == 1 |
| 1076 | assert isinstance(model.a, Item) |
| 1077 | assert model.other == "foo" |
| 1078 | |
| 1079 | |
| 1080 | # NOTE: Workaround for Pydantic Iterable behavior. |
nothing calls this directly
no test coverage detected