Repository navigation
Fix quoted string keys breaking extract() and Delta - #673
Open
tony1233200 wants to merge 1 commit into
Open
tony1233200 wants to merge 1 commit into
tony1233200 wants to merge 1 commit into
Conversation
Keys containing both single and double quotes produced paths that parse_path(), extract() and Delta could not consume. Emit such keys as explicit u-prefixed Python string literals and teach the path parser to recognize them, keeping legacy raw-backslash paths intact. Fixes qlustered#648
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.
Fix quoted string keys breaking extract() and Delta
Fixes #648.
Problem
A dictionary key containing both single and double quotes (e.g.
Bob's "plan") produced a path thatparse_path(),extract()andDeltacould not consume:Root cause
stringify_element()replaced both quote types in such a key with the𝆺𝅥𝅯marker and wrapped the result in double quotes, producing a path the parser cannot split back into the original key. The same failure occurred for added/removed quoted keys.Change
deepdiff/path.pyonly:u-prefixed Python string literals (str.__repr__), so the parser can recover them exactly withliteral_eval. This keeps legacy raw-backslash path spellings intact, including keys ending in a backslash._path_to_elements()recognizes theu'...'/u"..."literal at the start of a bracket segment and parses it as one element.str.__repr__(not the subclass's custom__repr__).Compatibility note (for the maintainer)
As noted in #648, this changes the canonical spelling of previously malformed paths: old paths that only ever worked as opaque
exclude_pathsstrings will no longer match under the new spelling, while exclusions regenerated from the new output work. Ordinary keys, single-quote-type keys and old raw-backslash paths keep their existing spelling and parsing. Happy to adjust the approach if a different compatibility direction is preferred.Tests
tests/test_path.py: new round-trip tests for both-quote keys (changed/added/removed), existing-spelling keys, nested keys, keys followed by attributes, andstrsubclass keys — 21 new parametrized cases.tests/test_diff_text.py: updatedtest_diff_quote_and_double_quote_in_stringexpectation to the new spelling.extractraisedKeyErrorandDeltaraisedDeltaError; after the fixextractreturns2andDeltaround-trips (old + delta == new,new - delta == old).pytest tests/— 1380 passed, 45 skipped, 0 failed.flake8on the touched files reports the same 64 pre-existing findings as the clean tree — no new violations.Notes
dev, where it applies cleanly); I ported it to the current tree, verified the repro, and ran the full suite.