Skip to content

Commit 3228f4b

Browse files
committed
leaving notes for the future
1 parent e8fd305 commit 3228f4b

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

deepdiff/diff.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,6 @@ def _diff_by_forming_pairs_and_comparing_one_by_one(
845845
t1_from_index=None, t1_to_index=None,
846846
t2_from_index=None, t2_to_index=None,
847847
):
848-
849848
for (i, j), (x, y) in self._get_matching_pairs(
850849
level,
851850
t1_from_index=t1_from_index, t1_to_index=t1_to_index,
@@ -894,6 +893,8 @@ def _diff_by_forming_pairs_and_comparing_one_by_one(
894893
# is relative to t2.
895894
reference_param1 = j
896895
reference_param2 = i
896+
else:
897+
continue
897898

898899
item_id = id(x)
899900
if parents_ids and item_id in parents_ids:
@@ -918,6 +919,10 @@ def _diff_ordered_iterable_by_difflib(
918919

919920
opcodes = seq.get_opcodes()
920921
opcodes_with_values = []
922+
923+
# TODO: this logic should be revisted so we detect reverse operations
924+
# like when a replacement happens at index X and a reverse replacement happens at index Y
925+
# in those cases we have a "iterable_item_moved" operation.
921926
for tag, t1_from_index, t1_to_index, t2_from_index, t2_to_index in opcodes:
922927
if tag == 'equal':
923928
opcodes_with_values.append(Opcode(

deepdiff/helper.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,7 @@ class OpcodeTag(EnumBase):
739739
delete = 'delete'
740740
equal = 'equal'
741741
replace = 'replace'
742+
# swapped = 'swapped' # in the future we should support reporting of items swapped with each other
742743

743744

744745
class Opcode(NamedTuple):

tests/test_diff_text.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1744,6 +1744,15 @@ def test_list_item_removed_from_the_middle(self):
17441744
assert {"root[4]"} == diff.affected_paths
17451745
assert {4} == diff.affected_root_keys
17461746

1747+
# TODO: we need to support reporting that items have been swapped
1748+
# def test_item_moved(self):
1749+
# # currently all the items in the list need to be hashables
1750+
# t1 = [1, 2, 3, 4]
1751+
# t2 = [4, 2, 3, 1]
1752+
# diff = DeepDiff(t1, t2)
1753+
# result = {} # it should show that those items are swapped.
1754+
# assert result == diff
1755+
17471756
def test_list_item_values_replace_in_the_middle(self):
17481757
t1 = [0, 1, 2, 3, 'bye', 5, 6, 7, 8, 'a', 'b', 'c']
17491758
t2 = [0, 1, 2, 3, 'see', 'you', 'later', 5, 6, 7, 8, 'a', 'b', 'c']

0 commit comments

Comments
 (0)