Skip to content
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

Support in-place patch/revert #91

Closed
mikaelho opened this issue Mar 30, 2017 · 4 comments
Closed

Support in-place patch/revert #91

mikaelho opened this issue Mar 30, 2017 · 4 comments

Comments

@mikaelho
Copy link
Contributor

I request adding an in-place patch/revert capability, i.e. option for performing these operations without copying the target structure.

This would be a useful performance optimization in some large-volume use cases. I also have a functional need of patching in place while recording all changes made to the structure.

This could be implemented as an additional, optional parameter to patch and revert:

Patch:

def patch(diff_result, destination, in_place=False):
    """Docstring"""
    if not in_place:
      destination = copy.deepcopy(destination)

Revert:

def revert(diff_result, destination, in_place=False):
    """Docstring"""
    return patch(swap(diff_result), destination, in_place)

And tested with e.g.

a = {
  'a' : 1
}
b = {
  'a' : 2
}
changes = list(diff(a, b))

c = patch(changes, a)
assert a != c

d = revert(changes, c, in_place=True)
assert a == d
assert c == d

e = patch(changes, a, in_place=True)
assert a == e
@jirikuncar
Copy link
Member

@mikaelho are you willing to send a pull-request with proposed tests?

@mikaelho
Copy link
Contributor Author

Never done it before. I will try.

@jirikuncar
Copy link
Member

@mikaelho don't worry 😉 Just have a look at some past commits to see how things are done. If you have any question just ping me.

@mikaelho
Copy link
Contributor Author

Done - my first pull request ever.

#92

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants