Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions jsonpatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -699,27 +699,29 @@ def __init__(self, src_doc, dst_doc, dumps=json.dumps, pointer_cls=JsonPointer):
root[:] = [root, root, None]

def store_index(self, value, index, st):
typed_key = (value, type(value))
try:
storage = self.index_storage[st]
stored = storage.get(value)
stored = storage.get(typed_key)
if stored is None:
storage[value] = [index]
storage[typed_key] = [index]
else:
storage[value].append(index)
storage[typed_key].append(index)

except TypeError:
self.index_storage2[st].append((value, index))
self.index_storage2[st].append((typed_key, index))

def take_index(self, value, st):
typed_key = (value, type(value))
try:
stored = self.index_storage[st].get(value)
stored = self.index_storage[st].get(typed_key)
if stored:
return stored.pop()

except TypeError:
storage = self.index_storage2[st]
for i in range(len(storage)-1, -1, -1):
if storage[i][0] == value:
if storage[i][0] == typed_key:
return storage.pop(i)[1]

def insert(self, op):
Expand Down
9 changes: 9 additions & 0 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,15 @@ def test_issue90(self):
self.assertEqual(res, dst)
self.assertIsInstance(res['A'], bool)

def test_issue129(self):
"""In JSON 1 is different from True even though in python 1 == True Take Two"""
src = {'A': {'D': 1.0}, 'B': {'E': 'a'}}
dst = {'A': {'C': 'a'}, 'B': {'C': True}}
patch = jsonpatch.make_patch(src, dst)
res = jsonpatch.apply_patch(src, patch)
self.assertEqual(res, dst)
self.assertIsInstance(res['B']['C'], bool)

def test_issue103(self):
"""In JSON 1 is different from 1.0 even though in python 1 == 1.0"""
src = {'A': 1}
Expand Down