Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# DeepDiff Change log

- Unreleased
- Fixed `DeepSearch(exclude_types=...)` applying type exclusions to the search term instead of the current object. Excluded root and nested objects are now skipped, while excluding the search term's type no longer suppresses matches on other object types (#629).
- Fixed missing type changes between equal-comparing items inside ordered iterables, e.g. `DeepDiff([2], [2.0])` now reports the `int` → `float` change like `DeepDiff(2, 2.0)` and `DeepDiff({'a': 2}, {'a': 2.0})` already do (issue #605).

- v9-1-0
Expand Down
2 changes: 1 addition & 1 deletion deepdiff/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ def __search_tuple(self, obj: Tuple[Any, ...], item: Any, parent: str, parents_i

def __search(self, obj: Any, item: Any, parent: str = "root", parents_ids: FrozenSet[int] = frozenset()) -> None:
"""The main search method"""
if self.__skip_this(item, parent):
if self.__skip_this(obj, parent):
return

elif isinstance(obj, strings) and isinstance(item, (strings, RE_COMPILED_TYPE)):
Expand Down
15 changes: 15 additions & 0 deletions tests/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,21 @@ def test_skip_type_str(self):
ds = DeepSearch(obj, item, verbose_level=1, exclude_types=[str])
assert ds == result

@pytest.mark.parametrize('obj', [[item], (item,), {'key': item}, CustomClass(item)])
def test_skip_root_object_type(self, obj):
assert DeepSearch(obj, item, exclude_types=[type(obj)]) == {}

@pytest.mark.parametrize('excluded', [[item], (item,), CustomClass(item)])
def test_skip_dictionary_value_type(self, excluded):
obj = {'skip': excluded, 'keep': item}
result = {'matched_values': {"root['keep']"}}
assert DeepSearch(obj, item, exclude_types=[type(excluded)]) == result

def test_excluding_item_type_does_not_skip_other_object_types(self):
obj = {'needle': 1, 'value': 'needle'}
result = {'matched_paths': {"root['needle']"}}
assert DeepSearch(obj, 'needle', exclude_types=[str]) == result

def test_skip_regexp(self):
obj = [{'a': 1, 'b': "somewhere"}, {'c': 4, 'b': "somewhere"}]
ds = DeepSearch(obj, item, exclude_regex_paths=[r"root\[\d+\]"])
Expand Down