fix: handle plain classes and callables in to_serializable

Add __dict__ handler for non-Pydantic classes so their attributes are
serialized rather than falling through to repr(). Guard with a callable
check so functions/lambdas still get repr().
This commit is contained in:
Greyson LaLonde
2026-03-31 15:59:43 +08:00
parent 19d1088bab
commit 47f192e112

View File

@@ -116,6 +116,23 @@ def to_serializable(
}
except Exception:
return repr(obj)
if callable(obj):
return repr(obj)
if hasattr(obj, "__dict__"):
try:
return {
_to_serializable_key(k): to_serializable(
v,
max_depth=max_depth,
_current_depth=_current_depth + 1,
_ancestors=new_ancestors,
context=context,
)
for k, v in obj.__dict__.items()
if not k.startswith("_")
}
except Exception:
return repr(obj)
return repr(obj)