Repository navigation
Conversation
Materialize input pairs once before validation so iterator updates retain their first item and validate all pairs before mutation. Add regressions for generators, inverse updates, collisions, and invalid inputs.
This was referenced Oct 2, 2026
Owner
|
Folded into #609 (see the PR description for credit). Thanks for the report and the repro. |
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 change
OneToOne.update()silently drops the first pair when its input is a one-shot iterator or generator:The validation loop consumes a pair and then calls
list()on the same iterator, saving only its remaining items. Those remaining items also miss validation before mutation, so an invalid later pair can leave an update partially applied.Materialize the input pairs once, validate that snapshot, then use the existing assignment path. This preserves keyword precedence and the forward/inverse mapping relationship without adding dependencies or changing the public signature.
The 20 added test cases cover empty/single/multiple inputs, mappings and sequences, iterators and generators, updates through the inverse, conflicting keys/values, and validation before mutation. Seven cases fail against the unchanged base revision; all pass with the fix.
Validation on Windows:
4e5faa3: 678 tests passed, plus 12 subtests.python -m pytest tests/test_dictutils_onetoone.py tests/test_dictutils.py -q: 50 passed.python -m tox -e py39,py312,py314 -- -q: 698 tests and doctests passed in each environment (CPython 3.9.13, 3.12.14, 3.14.0).check --select E9,Fon both changed files, Ruff format check with single quotes on the new test file,compileall, andgit diff --check: passed.Python 3.14 reports the same five unrelated deprecation warnings as the baseline. Linux/macOS and the remaining upstream interpreter matrix were not run locally.
The backstory
This PR was prepared by Codex on behalf of 9Kun, in response to a request for one useful open-source contribution. Source inspection while screening the existing dictionary utilities uncovered the iterator consumption bug; running the same pairs through a list and an iterator reproduced the silent data loss. Searches of existing issues and PRs found no corresponding fix; the open DotDict PR #387 does not change this method.
AI assistance
Original contribution request