Thoughts on modifiable_copy?
yuanxu-li opened this issue · 2 comments
yuanxu-li commented
from frozendict import frozendict
a = frozendict({'a': 1})
b = a.copy()
b['c'] = 1
throws the following error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'frozendict' object does not support item assignment
However, a common usage in my program is to copy over the unmodifiable frozendict to another place and do some modification. I wonder if we can provide a method called modifiable_copy
such that
from frozendict import frozendict
a = frozendict({'a': 1})
b = a.modifiable_copy()
b['c'] = 1
is allowed
ppolewicz commented
>>> import frozendict
>>> write_protected = frozendict.frozendict(a='foo', b='bar')
>>> write_enabled = dict(write_protected)
>>> write_protected
<frozendict {'b': 'bar', 'a': 'foo'}>
>>> write_enabled
{'b': 'bar', 'a': 'foo'}
>>> write_enabled['c'] = 'baz'
>>> write_enabled
{'b': 'bar', 'c': 'baz', 'a': 'foo'}
>>>
Marco-Sulla commented
Yes, there's no need of another method, you can simply convert to dict
.