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