Skip to content

Commit f1d87e9

Browse files
committed
fixes #509
1 parent 5120230 commit f1d87e9

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

deepdiff/diff.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -616,11 +616,17 @@ def _diff_dict(
616616
t1_clean_to_keys = t2_clean_to_keys = None
617617

618618
t_keys_intersect = t2_keys & t1_keys
619-
t_keys_union = t2_keys | t1_keys
620619
t_keys_added = t2_keys - t_keys_intersect
621620
t_keys_removed = t1_keys - t_keys_intersect
621+
622622
if self.threshold_to_diff_deeper:
623-
if len(t_keys_union) > 1 and len(t_keys_intersect) / len(t_keys_union) < self.threshold_to_diff_deeper:
623+
if self.exclude_paths:
624+
t_keys_union = {f"{level.path()}[{repr(key)}]" for key in (t2_keys | t1_keys)}
625+
t_keys_union -= self.exclude_paths
626+
t_keys_union_len = len(t_keys_union)
627+
else:
628+
t_keys_union_len = len(t2_keys | t1_keys)
629+
if t_keys_union_len > 1 and len(t_keys_intersect) / t_keys_union_len < self.threshold_to_diff_deeper:
624630
self._report_result('values_changed', level, local_tree=local_tree)
625631
return
626632

tests/test_diff_text.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1533,6 +1533,10 @@ def test_skip_path2_reverse(self):
15331533
ddiff = DeepDiff(t2, t1, exclude_paths={"root['ingredients']"})
15341534
assert {} == ddiff
15351535

1536+
def test_exclude_path_when_prefix_of_exclude_path_matches1(self):
1537+
diff = DeepDiff({}, {'foo': '', 'bar': ''}, exclude_paths=['foo', 'bar'])
1538+
assert not diff
1539+
15361540
def test_include_path3(self):
15371541
t1 = {
15381542
"for life": "vegan",

0 commit comments

Comments
 (0)