Skip to content

Commit 346a41f

Browse files
Fix appending operation for list
1 parent 3e724b8 commit 346a41f

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

patchdiff/apply.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ def iapply(obj: Diffable, patches: List[Dict]) -> Diffable:
1919
else: # add/replace
2020
parent[key] = value
2121
elif hasattr(parent, "append"): # list
22-
key = int(key)
22+
try:
23+
key = int(key)
24+
except ValueError:
25+
pass
26+
2327
if op == "replace":
2428
parent[key] = value
2529
elif op == "add":

tests/test_apply.py

+13
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,16 @@ def test_apply():
2727

2828
d = apply(b, rops)
2929
assert a == d
30+
31+
32+
def test_add_remove_list():
33+
a = []
34+
b = [1]
35+
36+
ops, rops = diff(a, b)
37+
38+
c = apply(a, ops)
39+
assert c == b
40+
41+
d = apply(b, rops)
42+
assert a == d

0 commit comments

Comments
 (0)