Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deepfreeze must not modify original object #97

Merged
merged 3 commits into from
Apr 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading