Skip to content

Commit

Permalink
Temporarily fix handling of non-subscriptable iterables by pretending…
Browse files Browse the repository at this point in the history
… they are subscriptable
  • Loading branch information
victorhahncastell committed Aug 19, 2016
1 parent 76a150b commit 24bc125
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
4 changes: 3 additions & 1 deletion deepdiff/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,9 @@ def __diff_iterable(self, t1, t2, parent="root", parents_ids=frozenset({})):
if getattr(t1, '__getitem__') and getattr(t2, '__getitem__'):
return self.__diff_iterable_subscriptable(t1, t2, parent, parents_ids)
except AttributeError:
return # TODO
# Temporarily fix handling of non-subscriptable iterables by pretending they are subscriptable.
# See test for further comments.
return self.__diff_iterable_subscriptable(list(t1), list(t2), parent, parents_ids)

def __diff_iterable_subscriptable(self, t1, t2, parent="root", parents_ids=frozenset({})):
"""Difference of subscriptable iterables, like lists"""
Expand Down
22 changes: 22 additions & 0 deletions tests/test_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -891,3 +891,25 @@ def __str__(self):
ddiff = DeepDiff(t1, t2)
result = {'unprocessed': ['root: Bad Object and Bad Object']}
self.assertEqual(ddiff, result)

def test_non_subscriptable_iterable(self):
def gen1():
yield 42
yield 1337
yield 31337

def gen2():
yield 42
yield 1337

t1 = gen1()
t2 = gen2()
ddiff = DeepDiff(t1, t2)

result = {'iterable_item_removed': {'root[2]': 31337}}
# TODO: This should NOT be the expected behaviour. This is a non-subscriptable iterable.
# Something like generator[2] is just invalid.
# Should be more something like:
#result = {'iterable_item_removed': {'root': 31337}}
# But how to handle multiple changes then? {'root': {31337}}}?
self.assertEqual(ddiff, result)

0 comments on commit 24bc125

Please sign in to comment.