Skip to content

Commit fd9fa23

Browse files
committed
Merge branch 'master' of github.com:stefankoegl/python-json-patch
2 parents d1cfec3 + ce15b23 commit fd9fa23

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

jsonpatch.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -699,27 +699,29 @@ def __init__(self, src_doc, dst_doc, dumps=json.dumps, pointer_cls=JsonPointer):
699699
root[:] = [root, root, None]
700700

701701
def store_index(self, value, index, st):
702+
typed_key = (value, type(value))
702703
try:
703704
storage = self.index_storage[st]
704-
stored = storage.get(value)
705+
stored = storage.get(typed_key)
705706
if stored is None:
706-
storage[value] = [index]
707+
storage[typed_key] = [index]
707708
else:
708-
storage[value].append(index)
709+
storage[typed_key].append(index)
709710

710711
except TypeError:
711-
self.index_storage2[st].append((value, index))
712+
self.index_storage2[st].append((typed_key, index))
712713

713714
def take_index(self, value, st):
715+
typed_key = (value, type(value))
714716
try:
715-
stored = self.index_storage[st].get(value)
717+
stored = self.index_storage[st].get(typed_key)
716718
if stored:
717719
return stored.pop()
718720

719721
except TypeError:
720722
storage = self.index_storage2[st]
721723
for i in range(len(storage)-1, -1, -1):
722-
if storage[i][0] == value:
724+
if storage[i][0] == typed_key:
723725
return storage.pop(i)[1]
724726

725727
def insert(self, op):

tests.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,15 @@ def test_issue90(self):
481481
self.assertEqual(res, dst)
482482
self.assertIsInstance(res['A'], bool)
483483

484+
def test_issue129(self):
485+
"""In JSON 1 is different from True even though in python 1 == True Take Two"""
486+
src = {'A': {'D': 1.0}, 'B': {'E': 'a'}}
487+
dst = {'A': {'C': 'a'}, 'B': {'C': True}}
488+
patch = jsonpatch.make_patch(src, dst)
489+
res = jsonpatch.apply_patch(src, patch)
490+
self.assertEqual(res, dst)
491+
self.assertIsInstance(res['B']['C'], bool)
492+
484493
def test_issue103(self):
485494
"""In JSON 1 is different from 1.0 even though in python 1 == 1.0"""
486495
src = {'A': 1}

0 commit comments

Comments
 (0)