| 131 | |
| 132 | |
| 133 | def model_dump( |
| 134 | model: pydantic.BaseModel, |
| 135 | *, |
| 136 | exclude: IncEx | None = None, |
| 137 | exclude_unset: bool = False, |
| 138 | exclude_defaults: bool = False, |
| 139 | warnings: bool = True, |
| 140 | mode: Literal["json", "python"] = "python", |
| 141 | ) -> dict[str, Any]: |
| 142 | if PYDANTIC_V2 or hasattr(model, "model_dump"): |
| 143 | return model.model_dump( |
| 144 | mode=mode, |
| 145 | exclude=exclude, |
| 146 | exclude_unset=exclude_unset, |
| 147 | exclude_defaults=exclude_defaults, |
| 148 | # warnings are not supported in Pydantic v1 |
| 149 | warnings=warnings if PYDANTIC_V2 else True, |
| 150 | ) |
| 151 | return cast( |
| 152 | "dict[str, Any]", |
| 153 | model.dict( # pyright: ignore[reportDeprecated, reportUnnecessaryCast] |
| 154 | exclude=exclude, |
| 155 | exclude_unset=exclude_unset, |
| 156 | exclude_defaults=exclude_defaults, |
| 157 | ), |
| 158 | ) |
| 159 | |
| 160 | |
| 161 | def model_parse(model: type[_ModelT], data: Any) -> _ModelT: |