-
-
Notifications
You must be signed in to change notification settings - Fork 225
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Precompiled regex simple diff #413
Conversation
On this point, I believe the simplest place to add more granular info would be here. Something like the following:
The final diff output could then look something like the following:
This has the considerable drawback though of potentially stuffing lots of regex-specific code into More appropriate might be to create a custom method, or perhaps even a simple class, for handling regex-specific considerations/APIs. The question then would be the optimal place to put it... Curious for your thoughts on this @seperman, as I don't want to completely clobber your original design/vision here. |
Hi @cohml
That way it will also work better when serializing the output to formats that don't accept If you are cool with that, let's take care of it in the same PR. |
Oh awesome, that is perfect actually. In my own testing I had neglected to discover this as even a possibility. Much cleaner than my original proposal! Poking around, it actually seems possible to get this kind of output while even simplifying the implementation beyond what I've already pushed. I will push some updates shortly for review and ping you here. |
975cd2d
to
258ab0b
Compare
@seperman The following behavior is now implemented, as we discussed:
Coverage report:
In the process I also caught a bug in your if statements that caused booleans to undergo an additional unintended round of diffing. Let me know if you'd call for other changes. |
258ab0b
to
32ec182
Compare
Perfect! Thanks @cohml |
Overview
This PR contains a first pass at adding simple diff detection for precompiled regex. This fixes the bug referenced in #336. Questions/comments for @seperman in bold.
What this PR adds
deepdiff.DeepDiff
now returns a diff if twore.Pattern
objects consist of different patterns, flags, or groups.What this PR doesn't add
The diff doesn't provide any granular info on the specific difference(s), e.g., "the patterns + groups are the same and the flags are different".
I would like to implement this greater granularity, but perhaps you'd prefer to merge what this PR already does and just add that other stuff as a separate PR? Let me know.
Coverage report
Note 1:
_diff_booleans
One thing to note is that the precompiled regex detection relies on
DeepDiff._diff_booleans
. So now_diff_booleans
acts more like a_diff_booleans_and_precompiled_regex
.At first I had created a dedicated
DeepDiff._diff_precompiled_regex
method, but then realized that it was identical to_diff_booleans
which already exists. So I just reused_diff_booleans
to avoid bloating the code base.If you're okay with coopting
_diff_booleans
like this, we might as well collapse further and just doOtherwise, I can recreate my original
_diff_precompiled_regex
method, or entertain anything else you'd propose.Note 2:
Delta
JFYI, I did not touch the code in
deepdiff/delta.py
, because it seems to already work as is.If anything looks amiss there, let me know and I will update the PR.