Skip to content

Keep iterator-based matching predicates reusable - #412

Merged
dgilland merged 1 commit into
dgilland:developfrom
Gambit-Checkmate:fix/reusable-iterator-matchers
Nov 5, 2026
Merged

dgilland merged 1 commit into
dgilland:developfrom
Gambit-Checkmate:fix/reusable-iterator-matchers

Conversation

@Gambit-Checkmate

@Gambit-Checkmate Gambit-Checkmate commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #411.

Keep top-level iterator criteria reusable in matches, which also fixes iterator-valued patterns captured by matches_property. Previously the first evaluation consumed the source; later evaluations could see empty criteria and incorrectly return True. For example, filtering [[1, 2], [9, 9]] with matches(iter([1, 2])) returned both candidates.

Retain an unadvanced itertools.tee branch and evaluate a fresh branch on each call, following the existing #298 function-combinator approach. Construction remains lazy, mismatches short-circuit without reading an unused tail, and reiterable sources retain their existing live behavior. Replay retains the produced source values needed by later calls. This does not snapshot or copy arbitrary nested source graphs.

Add a short public doc clarification, regression/control tests and an unreleased changelog entry. No signatures, dependencies or generated chain files change; the existing AUTHORS credit is retained.

Validation

Windows / CPython 3.13.13:

  • Twelve focused cases: eight fail on pristine develop 12c6405, all twelve pass after the fix. Cover list iterators/generators, changing repeated candidates, filtering and retained result references, both predicate factories, construction laziness, short-circuiting before a raising tail, empty criteria and live list mutation.
  • Full unit/doctest suite: 3,177 passed, 100% coverage.
  • Full configured mypy check, Ruff lint/formatting, Sphinx with warnings as errors, source distribution/wheel builds and git diff --check: passed.
  • Fresh generated chain signatures match the unchanged checked-in stub.

Other Python versions/platforms were not run locally. Hosted Main run 41551853284 is in progress; its result is not yet claimed.

Origin and assistance

Found by source inspection, not a production incident. Checked all-state iterator/generator/matches searches, the open PR inventory, #298's lazy replay precedent and #306's separate missing-path correction before reporting this issue.

OpenAI Codex (GPT-6 family; exact deployment identifier unavailable) assisted with investigation, implementation and verification. The user requested independently useful, tested contributions and avoidance of duplicate work; no independent human review is claimed.

@coveralls

Copy link
Copy Markdown

Coverage Status

coverage: 100.0%. remained the same — Gambit-Checkmate:fix/reusable-iterator-matchers into dgilland:develop

@dgilland
dgilland merged commit 30fed1f into dgilland:develop Nov 5, 2026
12 checks passed
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.

Iterator-based matches predicates lose their criteria after use

3 participants