Repository navigation
Conversation
FanWu-ai
marked this pull request as ready for review
October 3, 2026 09:14
seperman
reviewed
Oct 15, 2026
seperman
left a comment
Member
There was a problem hiding this comment.
Static review: #638 Respect exclusions before reporting DeepSearch path matches
Summary: Adds self.__skip_this(obj_child, new_parent) to DeepSearch.__search_dict, before a dictionary key or attribute name is compared with the search term. Excluded paths (exact, glob and regex) and children of excluded types no longer show up in matched_paths. This fixes the reported problem.
Overlap with other PRs
- #629 (open) changes the type check at the top of
__searchfrom__skip_this(item, ...)to__skip_this(obj, ...). As the description says, the two PRs complement each other:- This PR alone also skips dictionary values and attributes of excluded types, because the new check is given
obj_child. But the root object is never type-checked, and__search(deepdiff/search.py:324) still checks the type of the search item. For example,DeepSearch([1], 1, exclude_types=[list])still reportsroot[0], and #629'stest_skip_root_object_typecases would still fail. - #629 alone still reports excluded keys in
matched_paths, so the new tests here would fail with only #629. - The two merge without a textual conflict (checked with
git merge-tree).
- This PR alone also skips dictionary values and attributes of excluded types, because the new check is given
- #632 (open) changes the line right after the new check (
new_parent_cased = ...,deepdiff/search.py:241here), andgit merge-treereports a textual conflict there. The fix is to keep both: this check, then #632'sor self.use_regexpcondition. - Nothing equivalent is on
dev.
Security
No security concerns found in static review.
Correctness
deepdiff/search.py:239-240: ondev,__search_dictreports a path match (lines 244-250 here) before any exclusion check, because exclusions are only checked inside__search. SoDeepSearch({'needle': 'x'}, 'needle', exclude_paths=["root['needle']"])returnsmatched_paths: {"root['needle']"}. Running the check before the report fixes this. The fix also covers attributes and namedtuples, since__search_objgoes through__search_dict(print_as_attribute=True).- Because the check is given
obj_child, a key whose value has an excluded type is no longer reported inmatched_pathseither. - Minor: each dictionary child now goes through
__skip_thistwice, once here and once at the top of__search(line 324). Glob parsing (_path_to_elements) islru_cached, and__search_iterablealready checks twice in the same way, so the extra cost should be small. - Optional:
parents_ids_added(line 236) could be computed after the new check, which avoids a frozenset union for every skipped child.
Tests
-
The new tests at
tests/test_search.py:263,:272and:281cover:- exact, glob (
root[*]['needle']) and regex path exclusions - attribute names
- an excluded value type
Each runs at verbosity levels 1 and 2. Following
dev's code, each case should produce an extramatched_pathsentry there, so the tests fail ondevand pass with this change. - exact, glob (
Suggestions
- Land this together with, or after, #629 so the root-object case and the item-type check in
__searchare fixed as well. - If both this and #632 are merged, the conflict on the neighbouring line needs resolving (see Overlap above).
AI-assisted static review; the code was not executed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
DeepSearch reports matching dictionary keys and attribute names before the recursive search checks exclusions. For example,
DeepSearch({'needle': 'x'}, 'needle', exclude_paths=["root['needle']"])currently reports the excluded path inmatched_paths.Check the child object and its path with the existing exclusion predicate before reporting a path match. Add ten regression cases covering exact, wildcard and regex path exclusions, attribute names, excluded child types, retained siblings, and both verbosity levels.
This complements #629: that change fixes the recursive current-object type check, while this fixes the earlier path-reporting step. All eight initial path-exclusion regressions still fail with #629's production change alone.
Validation on Linux, CPython 3.12.14:
pytest --cov=deepdiff --runslow --benchmark-disable -q: 1,319 passed, 8 skipped; 95% aggregate coverage.deepdiff/search.py.pyright deepdiff/search.py: 0 errors, 0 warnings.E9,F63,F7,F82andgit diff --check: passed.Other Python versions, operating systems, and hosted CI have not been validated locally.