Repository navigation
fix: dedupe identical NaN objects in append_unique, matching set semantics - #54
Open
rahul05ranjan wants to merge 2 commits into
Open
rahul05ranjan wants to merge 2 commits into
rahul05ranjan wants to merge 2 commits into
Conversation
…ntics
ExtendedSet compares bucket members with ==, but set membership
short-circuits on identity first (PyObject_RichCompareBool). The
original set(base)-based append_unique relied on that: the same
float('nan') object was deduplicated, and NaN != NaN made ExtendedSet
append it again. Compare identity-first so identical objects count as
equal in membership and insertion, like a plain set.
Co-authored-by: rahul05ranjan <[email protected]>
Co-authored-by: rahul05ranjan <[email protected]>
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.
Fixes #53
Summary
ExtendedSetbucket membership compares with==only, but CPython's set membership short-circuits on identity first (PyObject_RichCompareBoolusesx is y or x == y). The originalset(base)-basedappend_uniquerelied on that fast path; theExtendedSetrewrite silently dropped it, so the samefloat('nan')object is now appended again instead of being recognized as a duplicate:_insertand__contains__now compare identity-first via a small_is_or_equalhelper that mirrorsPyObject_RichCompareBool, restoring plain-setsemantics for identical objects whose__eq__is not reflexive. Two different NaN objects are still both kept, exactly as a plain set does.Validation
tests/strategy/test_list.py:test_strategy_append_unique_identical_nan— fails on un-fixed HEAD.test_extended_set_membership_identity_semantics— direct membership pin, fails on un-fixed HEAD.test_strategy_append_unique_distinct_nan_kept— pins the unchanged distinct-NaN behavior (passes both sides).append_uniqueunchanged for plain values, equal dicts, unhashable lists/tuples, and the Deduplicate incoming values in append_unique #46 repeated-incoming-values cases; same-object unhashables ([1],{"a": 1}) deduped as before.make ready-prnot run on this host (Black/validate-pyproject unavailable); CI to cover.Notes
This is complementary to (and intentionally does not overlap) #52, which addresses the uninitialized set storage inherited by the class. No shared hunks; branches are independent cuts off master.