Skip to content

Preserve one-shot pairs during OneToOne updates - #661

Open
Gambit-Checkmate wants to merge 2 commits into
mahmoud:masterfrom
Gambit-Checkmate:fix/onetoone-iterator-pairs
Open

Gambit-Checkmate wants to merge 2 commits into
mahmoud:masterfrom
Gambit-Checkmate:fix/onetoone-iterator-pairs

Conversation

@Gambit-Checkmate

@Gambit-Checkmate Gambit-Checkmate commented Oct 27, 2026 •

Copy link
Copy Markdown

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:

  • Full unit/doctest suite: 781 passed, 1 skipped, 22 subtests passed.
  • New-test Ruff E9/F and format, compileall and git diff checks passed.
  • Wheel and sdist builds passed. No version bump.
  • Other platforms/interpreters await upstream CI; no coverage percentage claimed.

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

  • Harness/tooling: OpenAI Codex, Git, GitHub CLI/API, Python, pytest and Ruff. Codex performed investigation, implementation, testing and submission.
  • Model(s): GPT-6 family; the exact deployment identifier is not exposed in this session.
  • Original prompt(s), relevant verbatim excerpts from the daily automation (the mailbox workflow and local memory path are omitted):

每天早上 8 点在本会话实际提交两个高质量的开源贡献 PR,把创建并获得 GitHub PR 链接作为每日完成目标。首批候选不合适时必须继续扩大仓库与问题搜索范围,不因候选重复、单个问题困难或尚未发现合适 issue 就结束;没有合适公开 issue 时可以检查代码、复现真实缺陷,确认无重复后报告问题并提交独立修复。

只有改动真实、有依据、验证充分且账号有权限时才推送分支并创建 PR;绝不降低 star 门槛,不提交空改动、无关改动、未经验证或重复 PR,尊重上游 AI 贡献和认领规则。

Hosted CI: Actions run 40424134254 is action_required for external-contribution approval. No hosted tests have executed for this head.

@Ekko82 Ekko82 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@Gambit-Checkmate

Copy link
Copy Markdown
Author

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 Ekko82 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OneToOne.update consumes one-shot key/value pairs during validation

2 participants