Set of collections with ability to freeze their items
Project description
pyfrozen

Set of collections with ability to freeze their items.
Installation
$ pip install pyfrozen
Usage
>>> from pyfrozen import FrozenDict, FrozenList
>>>
>>> fd = FrozenDict()
>>> fd['key_1'] = 'value_1'
>>> fd
<FrozenDict(frozen=False, {'key_1': 'value_1'})>
>>> fd.freeze()
>>> fd
<FrozenDict(frozen=True, {'key_1': 'value_1'})>
>>> fd['key_1'] = 'value_2'
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/pyfrozen/pyfrozen/frozendict.py", line 23, in __setitem__
self.assert_frozen()
File "/pyfrozen/pyfrozen/frozendict.py", line 45, in assert_frozen
raise RuntimeError('Cannot modify frozen dict')
RuntimeError: Cannot modify frozen dict
>>> fd
<FrozenDict(frozen=True, {'key_1': 'value_1'})>
>>>
>>> fl = FrozenList()
>>> fl.extend(['value_1', 'value_2'])
>>> fl
<FrozenList(frozen=False, ['value_1', 'value_2'])>
>>> fl.freeze()
>>> fl.pop()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/lib/python3.6/_collections_abc.py", line 997, in pop
del self[index]
File "/pyfrozen/pyfrozen/frozenlist.py", line 29, in __delitem__
self.assert_frozen()
File "/pyfrozen/pyfrozen/frozenlist.py", line 56, in assert_frozen
raise RuntimeError('Cannot modify frozen list')
RuntimeError: Cannot modify frozen list
>>> fl
<FrozenList(frozen=True, ['value_1', 'value_2'])>
>>>
Testing and linting
For testing and linting install tox:
$ pip install tox
...and run:
$ tox
TODO
- Implement all collections using Cython
License
pyfrozen
is licensed under the MIT license. See the license file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pyfrozen-0.1.0.tar.gz
(3.3 kB
view hashes)
Built Distribution
Close
Hashes for pyfrozen-0.1.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8900bdb31d77a2420a35313bd84d7307a66657ecf53a05feb8670cc9db3761e2 |
|
MD5 | 07d90ae96b6aac21d87e25585029d4c9 |
|
BLAKE2b-256 | 3f82471baf1bab253d4627ed7bdabf84f4468aae46ee444407fa631dd89ed59a |