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

Thoughts on modifiable_copy? #22

Open
yuanxu-li opened this issue Aug 6, 2018 · 2 comments
Open

Thoughts on modifiable_copy? #22

yuanxu-li opened this issue Aug 6, 2018 · 2 comments

Comments

@yuanxu-li
Copy link

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
Copy link
Contributor

>>> 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
Copy link

Yes, there's no need of another method, you can simply convert to dict.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants