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

Function custom_pydantic_encoder

pydantic/v1/json.py:93–103  ·  view source on GitHub ↗
(type_encoders: Dict[Any, Callable[[Type[Any]], Any]], obj: Any)

Source from the content-addressed store, hash-verified

91
92
93def custom_pydantic_encoder(type_encoders: Dict[Any, Callable[[Type[Any]], Any]], obj: Any) -> Any:
94 # Check the class type and its superclasses for a matching encoder
95 for base in obj.__class__.__mro__[:-1]:
96 try:
97 encoder = type_encoders[base]
98 except KeyError:
99 continue
100
101 return encoder(obj)
102 else: # We have exited the for loop without finding a suitable encoder
103 return pydantic_encoder(obj)
104
105
106def timedelta_isoformat(td: datetime.timedelta) -> str:

Callers 1

test_deprecated_moduleFunction · 0.90

Calls 1

pydantic_encoderFunction · 0.70

Tested by 1

test_deprecated_moduleFunction · 0.72