Skip to content

Handle iterable operands consistently in set operations - #162

Open
mikamikasuki wants to merge 1 commit into
chaimleib:masterfrom
mikamikasuki:fix-set-operations-iterable-operands
Open

mikamikasuki wants to merge 1 commit into
chaimleib:masterfrom
mikamikasuki:fix-set-operations-iterable-operands

Conversation

@mikamikasuki

Copy link
Copy Markdown

IntervalTree documents iterable operands for its set operations, but intersection(iter(tree)) raises TypeError, and membership checks in difference and intersection_update can consume an iterator and return incorrect results. difference_update(tree) also raises RuntimeError when the operand is the tree itself.

Convert non-set operands once before membership queries, preserving existing set operands without copying them. Snapshot the operand for difference_update before mutation so aliases are safe. Regression tests cover iterators, generators, reusable containers, self-difference updates, and set operands whose iteration is counted.

Validation: all 132 tests and doctests pass on CPython 3.12.15 and 3.14.7. Seven regression cases fail before the fix. Separately, 32,000 comparisons against Python set operations pass on CPython 3.9 and 3.14, including mutable interval payloads and self operands; allocation checks confirm that set, frozenset, and IntervalTree operands are not copied by the three query methods. The configured fatal-error flake8 check passes.

Implementation and validation were produced with an AI coding agent.

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.

1 participant