Repository navigation
Fix unique handling of literal index-like keys - #666
Open
tanveerchana wants to merge 1 commit into
Open
tanveerchana wants to merge 1 commit into
tanveerchana wants to merge 1 commit into
Conversation
Compare stored item values and remove duplicate raw keys through BaseDict so unique cannot pop an unrelated nested list element. Preserve frozen and wrapped dictionary behavior and add regression coverage. AI assistance: implemented and tested with OpenAI Codex.
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.
Describe your changes
unique()currently interprets stored dictionary keys as paths when reading values and removing duplicates. A literal key such asrows[0]can therefore cause an unrelated list element to be deleted:Iterate over a snapshot of stored items and remove duplicate literal keys through
BaseDict.pop, preserving wrapped-dictionary updates and frozen-input checks. Keep the genericMutableMappingfallback. Regression tests cover wrapped/unwrapped dictionaries, a distinct literal value, a missing path parent with unhashable duplicates, and frozen input.Related issue
No matching existing issue or PR found. Reproduced during code inspection on main
e910141, python-benedict 0.40.1, CPython 3.12.14/Linux. This is independently reproduced behavior, not a claimed production incident.Validation
python -m pytest tests/core/test_unique.py tests/dicts/test_benedict.py -q: 96 passed, 7 subtests passed.pre-commit run --files benedict/core/unique.py tests/dicts/test_benedict.py: all applicable hooks passed.ruff check .andruff format --check .: passed (197 files formatted).mypy benedict: passed, 65 source files.coverage run --source=benedict -m unittest: 994 tests run; 8 errors from existing remote fixture downloads blocked by the environment proxy (HTTP CONNECT 403). These affect plist, query-string, toml, xls/xlsx/xlsm, xml and yaml URL tests. No full-suite success is claimed. AWS credentials were left unset so existing live S3 tests did not perform transfers.python -m pytest -q -k 'not url': 947 passed, 47 deselected, 185 subtests passed (URL tests excluded).coverage report --include=benedict/core/unique.py: 100% statement coverage.Checklist before requesting a review