Skip to content

Commit

Permalink
Fix #245, never introduce new nodes during discard
Browse files Browse the repository at this point in the history
  • Loading branch information
tobgu committed Oct 22, 2023
1 parent 3fa47c2 commit 07d60a5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pyrsistent/_transformations.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ def _update_structure(structure, kvs, path, command):
for k, v in kvs:
is_empty = False
if v is _EMPTY_SENTINEL:
if command is discard:
# If nothing there when discarding just move on, do not introduce new nodes
continue

# Allow expansion of structure but make sure to cover the case
# when an empty pmap is added as leaf node. See #154.
is_empty = True
Expand Down
5 changes: 5 additions & 0 deletions tests/transform_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,8 @@ def test_discard_multiple_elements_in_pvector():
def test_transform_insert_empty_pmap():
m = pmap().transform(['123'], pmap())
assert m == pmap({'123': pmap()})


def test_discard_does_not_insert_nodes():
m = freeze({}).transform(['foo', 'bar'], discard)
assert m == pmap({})

0 comments on commit 07d60a5

Please sign in to comment.