File tree Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -288,7 +288,9 @@ def _serialize_node_impl(
288
288
else safe_repr (obj )
289
289
)
290
290
291
- elif isinstance (obj , Mapping ):
291
+ elif isinstance (obj , Mapping ) and type (obj ).__repr__ in (
292
+ object .__repr__ , dict .__repr__
293
+ ):
292
294
# Create temporary copy here to avoid calling too much code that
293
295
# might mutate our dictionary while we're still iterating over it.
294
296
obj = dict (iteritems (obj ))
Original file line number Diff line number Diff line change @@ -64,3 +64,13 @@ def test_bytes_serialization_repr(message_normalizer):
64
64
def test_serialize_sets (extra_normalizer ):
65
65
result = extra_normalizer ({1 , 2 , 3 })
66
66
assert result == [1 , 2 , 3 ]
67
+
68
+
69
+ def test_serialize_custom_mapping (extra_normalizer ):
70
+ class CustomReprDict (dict ):
71
+ def __repr__ (self ):
72
+ return "custom!"
73
+
74
+ result = extra_normalizer (CustomReprDict (one = 1 , two = 2 ))
75
+ assert result == "custom!"
76
+
You can’t perform that action at this time.
0 commit comments