diff --git a/deepdiff/search.py b/deepdiff/search.py index 9b1b11a1..79e0d9c1 100644 --- a/deepdiff/search.py +++ b/deepdiff/search.py @@ -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)): diff --git a/tests/test_search.py b/tests/test_search.py index 3984349a..c91f5911 100644 --- a/tests/test_search.py +++ b/tests/test_search.py @@ -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+\]"])