MCPcopy
hub / github.com/pydantic/pydantic / custom_pydantic_encoder

Function custom_pydantic_encoder

pydantic/deprecated/json.py:117–132  ·  view source on GitHub ↗
(type_encoders: dict[Any, Callable[[type[Any]], Any]], obj: Any)

Source from the content-addressed store, hash-verified

115 category=None,
116)
117def custom_pydantic_encoder(type_encoders: dict[Any, Callable[[type[Any]], Any]], obj: Any) -> Any:
118 warnings.warn(
119 '`custom_pydantic_encoder` is deprecated, use `BaseModel.model_dump` instead.',
120 category=PydanticDeprecatedSince20,
121 stacklevel=2,
122 )
123 # Check the class type and its superclasses for a matching encoder
124 for base in obj.__class__.__mro__[:-1]:
125 try:
126 encoder = type_encoders[base]
127 except KeyError:
128 continue
129
130 return encoder(obj)
131 else: # We have exited the for loop without finding a suitable encoder
132 return pydantic_encoder(obj)
133
134
135@deprecated('`timedelta_isoformat` is deprecated.', category=None)

Callers

nothing calls this directly

Calls 1

pydantic_encoderFunction · 0.70

Tested by

no test coverage detected