Repository navigation
Conversation
Owner
|
Folded into #609 (see the PR description for credit). Thanks for the report and the repro. |
blebo
pushed a commit
to blebo/boltons
that referenced
this pull request
Nov 1, 2026
…tor set ops, complement & and ^ (mahmoud#577, mahmoud#535, mahmoud#494, mahmoud#503, mahmoud#516, mahmoud#487)
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.
The change
Correct three intersection branches in
setutils.complement:&=intersects a complement with a finite set, switch to the included representation.&=intersects an included-form set with a complement, keep the included representation.For example,
complement(complement({1, 2})) & complement({2, 3})currently yields{3}instead of{1}. Also, aftervalue = complement({1, 2}); value &= {2, 3}, the result currently excludes3and contains unrelated values such as0, instead of being the finite set{3}.The fix preserves in-place object identity and leaves the right operand unchanged. It adds 148 regression/control cases covering ordinary sets, both complement representations, set/frozenset backing, overlapping/disjoint/equal/empty inputs, reversed operands, the method API, and self-intersection. Expected membership is computed using ordinary sets, including probes outside both inputs.
Validation on Windows, Python 3.13.15:
twine check,pip check, andgit diff --checkpassed.Other Python/OS combinations have not been run locally. This is separate from #487 (symmetric difference) and #494/#503 (IndexedSet operations).
The backstory
This is @hansu650's first PR to boltons, prepared by Codex on a request to find and submit a tested Python contribution. The defect was found during source review of the set-like API, not in a production incident or long-term use of boltons. The documented goal of following standard-library conventions made ordinary set membership a useful reference for checking these branches.
AI assistance
Codex checked contribution guidance and existing PRs, reproduced the failures, implemented the fix and tests, ran validation, and drafted/submitted this PR. No independent human code review is claimed.