Repository navigation
Compare read-only containers recursively in test operations - #257
Merged
stefankoegl merged 2 commits intoNov 10, 2026
Merged
Conversation
Copilot stopped reviewing on behalf of
stefankoegl due to an error
November 9, 2026 05:44
Contributor
There was a problem hiding this comment.
Note
Copilot was unable to run its full agentic suite in this review.
Copilot review overview
2 open issues
What changed in this PR
This PR updates JSON Patch test operation equality semantics so read-only mapping types (e.g., MappingProxyType) are compared structurally instead of via Python’s default equality, preventing True/1 and False/0 from being treated as equal.
Changes:
- Broaden
_json_equalmapping comparison fromMutableMappingtoMapping. - Add regression tests ensuring
testfails for bool-vs-int mismatches on read-only mappings and does not mutate input documents on success/failure.
| File | Description |
|---|---|
jsonpatch.py |
Fixes _json_equal to structurally compare read-only mappings, preserving RFC6902 bool/number distinction. |
tests.py |
Adds regression coverage for MappingProxyType and nested read-only mapping scenarios (success and failure). |
Review effort: Lite
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.

Whole read-only containers can fall back to Python equality instead of applying JSON equality recursively. For example,
MappingProxyType({'a': True})passes a roottestagainst{'a': 1}, and(True,)passes against(1,). Equivalent list and tuple values can also compare unequal.Use
Mappingand non-textSequencein_json_equal. Both are already accepted by the module and documented in its stubs; immutable sequences are also handled by the existing restoration code. Objects and arrays are compared recursively under the RFC 6902 rules. Strings and bytes remain scalar values, and mutation requirements are unchanged.Regression coverage includes root and nested read-only mappings, tuple/list comparisons in both directions, a generic read-only sequence, Boolean/number rejection, numeric
1/1.0equivalence, length/order differences, text/bytes exclusions, and preservation of input identity and content. The sequence follow-up adds 95 subcases; 33 fail on the previous PR revision and pass after the fix.Validation on Windows / Python 3.13.4:
python tests.py: 322 tests run, OK (1 skipped).python property_tests.py: 26 tests, OK.git diff --check: passed.Earlier validation: a 5,000-example single-process stress run hit a Hypothesis MemoryError and replay error; the affected two properties each passed at the same budget in fresh processes. On the previous CI revision, all unit-test and property-test matrix steps passed; coverage-upload jobs failed while downloading the Coveralls binary/checksum.