Marco-Sulla / python-frozendict

A simple immutable dictionary for Python
https://github.com/Marco-Sulla/python-frozendict
GNU Lesser General Public License v3.0
133 stars 16 forks source link

[BUG] `deepfreeze` modifies the original `dict` #96

Closed kenodegard closed 6 months ago

kenodegard commented 6 months ago

Welcome! You should write in your Bug Report:

OS version (https://www.google.com/search?channel=fs&q=check+os+version&ie=utf-8&oe=utf-8): macOS 14.3

Python3 version (python3 -V -V): Python 3.12.2

Steps to reproduce:

  1. Create some nested dict and call deepfreeze on it.

Actual result (with the python stack trace if present):

>>> o = {'a': 1, 'nested': {'b': 2}}
>>> d = deepfreeze(o)
>>> d
frozendict.frozendict({'a': 1, 'nested': frozendict.frozendict({'b': 2})})
>>> o
{'a': 1, 'nested': frozendict.frozendict({'b': 2})}

I expected deepfreeze to leave the original object untouched.

Marco-Sulla commented 6 months ago

Well, that's why is called deepfreeze. If you want to freeze only the main object, do

d = frozendict.frozendict(o)
kenodegard commented 6 months ago

But frozendict will only make the outter most object immutable.

Isn't the goal of deepfreeze to create a recursively immutable object?

I'm not understanding why deepfreeze should have any affect the original data structure.

Marco-Sulla commented 6 months ago

I'm not understanding why deepfreeze should have any affect the original data structure.

Can you please provide the expected output?

Marco-Sulla commented 6 months ago

Sorry for misunderstanding, the patch will be released in v2.4.2

Marco-Sulla commented 6 months ago

v2.4.2 released on Pypi and on Conda