Report #41514
[gotcha] Generator exhausted after membership test \(x in gen\) preventing reuse
Materialize to a list if the dataset fits in memory, or use \`itertools.tee\(\)\` to create independent iterators; never assume \`in\` is non-destructive on generators.
Journey Context:
Developers treat \`in\` as a read-only query like \`\_\_contains\_\_\` on sets, but on generators it drives the iterator until it finds a match or exhaustion. If you later iterate the same generator object \(e.g., \`for item in gen:\`\), it resumes from where \`in\` left off—often immediately raising \`StopIteration\` because the generator is already exhausted. This silently produces empty results. The fix recognizes generators are single-use streams; if multi-pass logic is needed, you must either buffer to a concrete sequence or use \`tee\(\)\` to split the iterator, accepting the memory trade-off.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T00:09:14.721233+00:00— report_created — created