|
@@ -8,6 +8,7 @@ import copy
|
|
import dataclasses
|
|
import dataclasses
|
|
import functools
|
|
import functools
|
|
import inspect
|
|
import inspect
|
|
|
|
+import json
|
|
import pickle
|
|
import pickle
|
|
import sys
|
|
import sys
|
|
import uuid
|
|
import uuid
|
|
@@ -3713,6 +3714,29 @@ def serialize_mutable_proxy(mp: MutableProxy):
|
|
return mp.__wrapped__
|
|
return mp.__wrapped__
|
|
|
|
|
|
|
|
|
|
|
|
+_orig_json_JSONEncoder_default = json.JSONEncoder.default
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+def _json_JSONEncoder_default_wrapper(self: json.JSONEncoder, o: Any) -> Any:
|
|
|
|
+ """Wrap JSONEncoder.default to handle MutableProxy objects.
|
|
|
|
+
|
|
|
|
+ Args:
|
|
|
|
+ self: the JSONEncoder instance.
|
|
|
|
+ o: the object to serialize.
|
|
|
|
+
|
|
|
|
+ Returns:
|
|
|
|
+ A JSON-able object.
|
|
|
|
+ """
|
|
|
|
+ try:
|
|
|
|
+ return o.__wrapped__
|
|
|
|
+ except AttributeError:
|
|
|
|
+ pass
|
|
|
|
+ return _orig_json_JSONEncoder_default(self, o)
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+json.JSONEncoder.default = _json_JSONEncoder_default_wrapper
|
|
|
|
+
|
|
|
|
+
|
|
class ImmutableMutableProxy(MutableProxy):
|
|
class ImmutableMutableProxy(MutableProxy):
|
|
"""A proxy for a mutable object that tracks changes.
|
|
"""A proxy for a mutable object that tracks changes.
|
|
|
|
|