Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
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
10 changes: 10 additions & 0 deletions tests/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,16 @@ 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_skip_regexp(self):
obj = [{'a': 1, 'b': "somewhere"}, {'c': 4, 'b': "somewhere"}]
ds = DeepSearch(obj, item, exclude_regex_paths=[r"root\[\d+\]"])
Expand Down