Repository navigation
Serialize and compare patches whose paths are pointer objects - #272
Open
stefankoegl wants to merge 1 commit into
Open
stefankoegl wants to merge 1 commit into
stefankoegl wants to merge 1 commit into
Conversation
The 'path' and 'from' of an operation can be given as pointer objects instead of strings. A JsonPatch created from such operations could be applied, but to_string() raised a TypeError, as its operations still contained the pointer objects, and it was not equal to the same patch given the paths as strings. JsonPatch now replaces pointer objects by their paths in its operations, in copies, so the operations it was created from are unchanged. Patch operations compare and hash by the paths as well. Their setters keep updating the operation they were created from. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PewzpjVeke4LTQ7Q88nyu6
This branch has not been deployed
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.
The
pathandfromof an operation can be given as pointer objects instead of strings. Such a patch could be applied, but:Changes
JsonPatchreplaces pointer objects by their paths inpatch.patch, soto_string(),str(), iteration,==andhash()all see strings. This is done in copies: the operation dicts the patch was created from keep their pointer objects.PatchOperation.__eq__and__hash__compare by the paths too, so an operation created directly with a pointer object equals one created with the string.What stays the same
A
PatchOperationstill shares the dict it was created from, also when that dict holds pointer objects, because its setters (key,from_key, …) write back into it and an existing test relies on that. My first attempt copied the dict there and broke that test, so the normalisation happens only inJsonPatchand in the comparisons.Visible change
patch.patchnow contains path strings where it used to contain the pointer objects that were passed in.Tests
Seven new tests: serialisation, equality and hashing of patches and of single operations, read-only mapping inputs, a pointer class with a different path syntax, the setters, and that the caller's operations are not modified.
python tests.pyandproperty_tests.pypass with coverage at 100%; flake8 is clean (Python 3.13).Generated by Claude Code