| 142 | |
| 143 | |
| 144 | def model_dump( |
| 145 | model: pydantic.BaseModel, |
| 146 | *, |
| 147 | exclude: IncEx | None = None, |
| 148 | exclude_unset: bool = False, |
| 149 | exclude_defaults: bool = False, |
| 150 | warnings: bool = True, |
| 151 | mode: Literal["json", "python"] = "python", |
| 152 | by_alias: bool | None = None, |
| 153 | ) -> dict[str, Any]: |
| 154 | if (not PYDANTIC_V1) or hasattr(model, "model_dump"): |
| 155 | kwargs: _ModelDumpKwargs = {} |
| 156 | if by_alias is not None: |
| 157 | kwargs["by_alias"] = by_alias |
| 158 | return model.model_dump( |
| 159 | mode=mode, |
| 160 | exclude=exclude, |
| 161 | exclude_unset=exclude_unset, |
| 162 | exclude_defaults=exclude_defaults, |
| 163 | # warnings are not supported in Pydantic v1 |
| 164 | warnings=True if PYDANTIC_V1 else warnings, |
| 165 | **kwargs, |
| 166 | ) |
| 167 | return cast( |
| 168 | "dict[str, Any]", |
| 169 | model.dict( # pyright: ignore[reportDeprecated, reportUnnecessaryCast] |
| 170 | exclude=exclude, exclude_unset=exclude_unset, exclude_defaults=exclude_defaults, by_alias=bool(by_alias) |
| 171 | ), |
| 172 | ) |
| 173 | |
| 174 | |
| 175 | def model_parse(model: type[_ModelT], data: Any) -> _ModelT: |