Repository navigation
Do not run custom operators on excluded paths - #676
Open
tony1233200 wants to merge 1 commit into
Open
tony1233200 wants to merge 1 commit into
tony1233200 wants to merge 1 commit into
Conversation
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.
Fixes #633
Custom operators were invoked on paths excluded via
exclude_paths, even though the comparison result was then discarded. For example, withexclude_paths=["root['b']"],give_up_diffingwas still called forroot['b'], so operators paid the cost of the comparison (and any of its side effects) for a path the user asked to skip:Changes
deepdiff/diff.py(DeepDiff._diff): when custom operators are set, the exclusion check (_skip_this, which coversexclude_paths/exclude_regex_paths/include_paths/exclude_types/ callbacks) now runs before_use_custom_operator, so operators never see an excluded level. When no custom operators are set, the check stays in its original position, so behaviour for plain diffs is unchanged.tests/test_operators.py: newtest_custom_operator_not_applied_to_excluded_pathreproducing the issue (records the paths the operator is invoked on; asserts onlyroot['a']is visited and the result is{}).Tests
devand passes with this change.devis 1344 passed, 45 skipped; the +1 is the new test).flake8on the touched files: no new violations (the remaining findings intests/test_operators.pyare pre-existing ondev).Notes
DeepDiff({b'k': 1}, {b'k': 2})already crashes on unmodifieddev(TypeErrorinstringify_elementwhen computing the path of a bytes-keyed level). That is a pre-existing issue in the same area, already covered by open PR Fix paths for bytes dictionary keys #640, so I deliberately did not touchpath.pyhere. This PR's reordering is guarded so the no-operator path is byte-for-byte the old order, keeping that pre-existing behaviour unchanged.