MCPcopy
hub / github.com/anthropics/anthropic-sdk-python / model_dump

Function model_dump

src/anthropic/_compat.py:144–172  ·  view source on GitHub ↗
(
    model: pydantic.BaseModel,
    *,
    exclude: IncEx | None = None,
    exclude_unset: bool = False,
    exclude_defaults: bool = False,
    warnings: bool = True,
    mode: Literal["json", "python"] = "python",
    by_alias: bool | None = None,
)

Source from the content-addressed store, hash-verified

142
143
144def 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
175def model_parse(model: type[_ModelT], data: Any) -> _ModelT:

Callers 7

test_unknown_fieldsFunction · 0.90
_build_requestMethod · 0.85
defaultMethod · 0.85
_transform_recursiveFunction · 0.85

Calls 1

model_dumpMethod · 0.80