Repository navigation
Preserve one-shot pairs during OneToOne updates - #661
Gambit-Checkmate wants to merge 2 commits into
Conversation
Ekko82
left a comment
There was a problem hiding this comment.
On base d31d821, a generator that overwrites and yields the same two-element list silently loses its earlier pairs. At 9a910be, the per-pair snapshot retains both entries, matching dict(pairs()), through either the forward or inverse mapping.
from boltons.dictutils import OneToOne
def pairs():
pair = [None, None]
for key, value in [("a", 1), ("b", 2)]:
pair[:] = [key, value]
yield pair
relation = OneToOne()
relation.update(pairs())
assert dict(relation) == {"a": 1, "b": 2}A shared-buffer regression would cover this silent data loss alongside the one-shot-iterator cases.
On Windows with Python 3.13.9, the seven PR tests plus six additional forward/inverse checks pass at this head. On the base, four one-shot cases and two shared-buffer cases fail. The extra checks also confirm that a late outer-generator exception or an unhashable key leaves both mappings unchanged. The full suite and package builds were not run.
|
Added the shared-buffer regression in e2a3092, parametrized for forward and inverse updates. It compares against dict(pairs()), checks both entries and inverse synchronization, and preserves inverse identity. The nine PR-specific cases pass; the full unit/doctest suite is 783 passed, 1 skipped, 22 subtests passed on Windows / CPython 3.13.13. Ruff E9/F and git diff checks passed. This is a test-only follow-up; the implementation is unchanged. Hosted tests still require upstream approval, so I am not claiming hosted execution. OpenAI Codex assisted with this follow-up. Thanks for the independent reproduction. |
Ekko82
left a comment
There was a problem hiding this comment.
Verified the two new shared-buffer parametrizations at e2a3092381173f1030e83daba73e51d549cc7ee9: both pass on Windows/Python 3.13.9 and both fail on base d31d821d56c8f7756af9c30a864077f2e5855321 with the earlier pair missing. The assertions cover both mappings and inverse identity. The implementation is unchanged from the previously reviewed head, so I reused the earlier 13-case results. I did not run the full suite or doctests.
The change
Closes #659.
Snapshot each input pair into a reusable tuple before validation. Materializing only the outer iterable leaves inner iterators consumed by validation, so valid dict-compatible inputs fail on the assignment pass. Existing prevalidation and inverse synchronization remain in use.
Four regressions fail before the change: outer lists/generators containing one-shot pairs, for forward and inverse updates. Three invalid-pair controls verify malformed pairs/unhashable values leave both mappings unchanged. This complements #523, already folded into #609, which fixed consumption of the outer iterable; it does not duplicate that fix or pending #614's optional update source.
Validation on Windows / CPython 3.13.13:
The backstory
Previous contribution #601 was acknowledged and incorporated in #609. This follow-up came from inspecting current master and comparing documented container behavior with builtin containers, not personal production usage. Existing related contributions were checked before filing the linked issue.
AI assistance
Hosted CI: Actions run 40424134254 is
action_requiredfor external-contribution approval. No hosted tests have executed for this head.