Skip to content

Retain the latest PSet evolver snapshot - #338

Open
36taransingh5-dotcom wants to merge 2 commits into
tobgu:masterfrom
36taransingh5-dotcom:fix-pset-evolver-snapshot
Open

36taransingh5-dotcom wants to merge 2 commits into
tobgu:masterfrom
36taransingh5-dotcom:fix-pset-evolver-snapshot

Conversation

@36taransingh5-dotcom

Copy link
Copy Markdown

Problem

After a PSet evolver is changed and materialized, calling persistent() again returns the original set instead of the latest snapshot:

from pyrsistent import pset

evolver = pset([1]).evolver()
evolver.add(2)
assert evolver.persistent() == pset([1, 2])
assert evolver.persistent() == pset([1, 2])  # fails on master: returns pset([1])

Materializing the underlying map clears its dirty state, but the set evolver's cached _original_pset still refers to the old set.

Change

Update the cached set when materializing a dirty evolver, then return that snapshot on subsequent calls. This follows the existing PMap evolver pattern. Add four regression cases covering add/remove snapshots, a no-op after a snapshot, and sequential snapshots that remain independent.

Validation

On Linux, Python 3.12.15:

  • The four new regression cases fail before the fix.
  • Full suite with the C extension: 641 passed, 1 skipped.
  • Full suite with PYRSISTENT_NO_C_EXTENSION=1: 540 passed, 102 skipped (backend-specific tests).
  • Module doctests: 80 passed.
  • Source distribution and wheel build succeeded.
  • git diff --check passed.

The published source and tests were read back and the suites rerun against those contents. This fix was found by source inspection and local reproduction, not a reported production incident.

AI assistance was used to investigate, implement, and test this contribution.

Store each newly materialized PSet as the evolver's current snapshot, matching PMap evolver behavior. Repeated persistent calls must not return an older set.
Cover repeated persistent calls after add/remove, a no-op following a snapshot, and sequential immutable snapshots.
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