Skip to content

Commit 5e514c5

Browse files
committed
serializing memoryview
1 parent 8121be3 commit 5e514c5

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

deepdiff/serialization.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,7 @@ def _serialize_tuple(value):
623623
Mapping: dict,
624624
NotPresent: str,
625625
ipranges: str,
626+
memoryview: lambda x: x.tobytes(),
626627
}
627628

628629
if PydanticBaseModel is not pydantic_base_model_type:

tests/test_serialization.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,8 @@ def prefix_callback(**kwargs):
418418
(6, datetime.datetime(2023, 10, 11), datetime.datetime.fromisoformat),
419419
(7, datetime.datetime.utcnow(), datetime.datetime.fromisoformat),
420420
(8, field_stats1, lambda x: SomeStats(**x)),
421-
(9, np.array([[ 101, 3533, 1998, 4532, 2024, 3415, 1012, 102]]), np.array)
421+
(9, np.array([[ 101, 3533, 1998, 4532, 2024, 3415, 1012, 102]]), np.array),
422+
(10, memoryview(b"hello"), lambda x: memoryview(x.encode('utf-8'))),
422423
])
423424
def test_json_dumps_and_loads(self, test_num, value, func_to_convert_back):
424425
serialized = json_dumps(value)
@@ -444,4 +445,3 @@ def test_reversed_list(self):
444445

445446
assert '[3,2,1]' == serialized
446447
assert '[3,2,1]' == serialized2, "We should have copied the original list. If this returns empty, it means we exhausted the original list."
447-

0 commit comments

Comments
 (0)