Skip to content

Preserve element identity in PList equality and removal - #339

Open
hakarrr wants to merge 4 commits into
tobgu:masterfrom
hakarrr:fix-plist-element-identity
Open

hakarrr wants to merge 4 commits into
tobgu:masterfrom
hakarrr:fix-plist-element-identity

Conversation

@hakarrr

@hakarrr hakarrr commented Oct 24, 2026

Copy link
Copy Markdown

Summary

PList documents standard list equality semantics, but a list containing a NaN can compare unequal to itself. The same object is found by membership/counting yet cannot be removed:

value = float('nan')
items = plist([value])
items == items          # False before this change
value in items          # True
items.remove(value)     # ValueError before this change

Check element identity before calling equality in PList.__eq__ and PList.remove. Distinct objects still use their existing equality behavior, including exceptions. This also fixes PDeque.remove, which delegates to its persistent lists. No list conversion or change to structural sharing is needed.

This is separate from #330's PMap bucket matching, #337's suffix slicing and the PDeque maxlen/slicing/rotation proposals.

Validation

  • 18 added cases: 15 fail against the unchanged implementation, 3 controls pass. Cases cover NaN, custom nonreflexive elements, identity avoiding an unnecessary raising comparison, distinct-element equality/exception behavior, hash/dict lookup consistency, unchanged originals, and removal from both PDeque halves.
  • Full suite with the actual compiled C extension: 655 passed, 1 existing skip on Linux CPython 3.10.12 and 3.12.15.
  • Pure-Python configuration on 3.12: 554 passed, 102 existing C-extension skips.
  • Module doctests: all 80 passed.
  • Wheel and sdist builds, git diff --check: passed.

The existing Hypothesis collection warning remains. Other Python versions, PyPy, platforms and the memory-profile job were not run locally. Hosted CI results remain separate.

AI-assisted implementation and testing.

Add tests for equality and removal of identical and non-reflexive elements in plist.
Add test for removing identical NaN values from pdeque.
Added a note about preserving element identity in PList.
@hakarrr

hakarrr commented Oct 29, 2026

Copy link
Copy Markdown
Author

Could you take a look at this PList identity/equality fix when you have time? The regression cases cover NaN, raising comparisons and PDeque removal while preserving the original persistent values. Local compiled-extension, pure-Python and doctest results are recorded above; hosted tests still require maintainer approval. Please let me know if any changes are needed for review. Thanks.

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