Repository navigation
Keep iterator-based matching predicates reusable - #412
Merged
dgilland merged 1 commit intoNov 5, 2026
Merged
Conversation
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.
Summary
Fixes #411.
Keep top-level iterator criteria reusable in
matches, which also fixes iterator-valued patterns captured bymatches_property. Previously the first evaluation consumed the source; later evaluations could see empty criteria and incorrectly returnTrue. For example, filtering[[1, 2], [9, 9]]withmatches(iter([1, 2]))returned both candidates.Retain an unadvanced
itertools.teebranch 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:
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.git diff --check: passed.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.