Skip to content

Commit ff5ddac

Browse files
authored
Merge pull request #2 from akshat62/tucdyf-codex/update-diff-behavior-for-item-movements
Detect moved items in ordered iterables
2 parents 6068470 + 34e22af commit ff5ddac

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

deepdiff/diff.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -896,8 +896,9 @@ def _diff_iterable_in_order(self, level, parents_ids=frozenset(), _original_type
896896
child_relationship_class=child_relationship_class,
897897
local_tree=local_tree_pass,
898898
)
899+
has_moves = bool(local_tree_pass['iterable_item_moved'])
899900
# Sometimes DeepDiff's old iterable diff does a better job than DeepDiff
900-
if len(local_tree_pass) > 1:
901+
if len(local_tree_pass) > 1 and not has_moves:
901902
local_tree_pass2 = TreeResult()
902903
self._diff_by_forming_pairs_and_comparing_one_by_one(
903904
level,
@@ -910,6 +911,8 @@ def _diff_iterable_in_order(self, level, parents_ids=frozenset(), _original_type
910911
local_tree_pass = local_tree_pass2
911912
else:
912913
self._iterable_opcodes[level.path(force=FORCE_DEFAULT)] = opcodes_with_values
914+
else:
915+
self._iterable_opcodes[level.path(force=FORCE_DEFAULT)] = opcodes_with_values
913916
for report_type, levels in local_tree_pass.items():
914917
if levels:
915918
self.tree[report_type] |= levels

0 commit comments

Comments
 (0)