Skip to main content

Set of collections with ability to freeze their items

Project description

pyfrozen Build Status codecov

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


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)

Uploaded source

Built Distribution

pyfrozen-0.1.0-py2.py3-none-any.whl (3.6 kB view hashes)

Uploaded py2 py3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page