Skip to content

Commit

Permalink
Merge pull request #97 from kenodegard/nested-deepfreeze
Browse files Browse the repository at this point in the history
`deepfreeze` must not modify original object
  • Loading branch information
Marco-Sulla committed Apr 13, 2024
2 parents d92551a + f448ba8 commit de41bda
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/frozendict/cool.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,8 @@ def deepfreeze(

o_copy = copy(o)

for k, v in getItems(o)(o_copy):
o[k] = deepfreeze(
for k, v in getItems(o_copy)(o_copy):
o_copy[k] = deepfreeze(
v,
custom_converters = custom_converters,
custom_inverse_converters = custom_inverse_converters
Expand All @@ -295,7 +295,7 @@ def deepfreeze(
else:
raise

return freeze(o)
return freeze(o_copy)


__all__ = (
Expand Down
12 changes: 11 additions & 1 deletion test/test_freeze.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,4 +181,14 @@ def test_prefer_forward():
custom_inverse_converters={FrozenSeqA: MutableSeq}
)[0],
FrozenSeqB
)
)

def test_original_immutate():
unfrozen = {
"int": 1,
"nested": {"int": 1},
}

frozen = cool.deepfreeze(unfrozen)

assert type(unfrozen["nested"]) is dict

0 comments on commit de41bda

Please sign in to comment.