5 .. image:: https://github.com/aio-libs/frozenlist/workflows/CI/badge.svg
6 :target: https://github.com/aio-libs/frozenlist/actions
7 :alt: GitHub status for master branch
9 .. image:: https://codecov.io/gh/aio-libs/frozenlist/branch/master/graph/badge.svg
10 :target: https://codecov.io/gh/aio-libs/frozenlist
11 :alt: codecov.io status for master branch
13 .. image:: https://badge.fury.io/py/frozenlist.svg
14 :target: https://pypi.org/project/frozenlist
15 :alt: Latest PyPI package version
17 .. image:: https://readthedocs.org/projects/frozenlist/badge/?version=latest
18 :target: https://frozenlist.readthedocs.io/
19 :alt: Latest Read The Docs
21 .. image:: https://img.shields.io/discourse/topics?server=https%3A%2F%2Faio-libs.discourse.group%2F
22 :target: https://aio-libs.discourse.group/
23 :alt: Discourse group for io-libs
25 .. image:: https://badges.gitter.im/Join%20Chat.svg
26 :target: https://gitter.im/aio-libs/Lobby
32 ``frozenlist.FrozenList`` is a list-like structure which implements
33 ``collections.abc.MutableSequence``. The list is *mutable* until ``FrozenList.freeze``
34 is called, after which list modifications raise ``RuntimeError``:
37 >>> from frozenlist import FrozenList
38 >>> fl = FrozenList([17, 42])
40 >>> fl.append('Vikings')
42 <FrozenList(frozen=False, [17, 42, 'spam', 'Vikings'])>
45 <FrozenList(frozen=True, [17, 42, 'spam', 'Vikings'])>
48 >>> fl.append("Monty")
49 Traceback (most recent call last):
50 File "<stdin>", line 1, in <module>
51 File "frozenlist/_frozenlist.pyx", line 97, in frozenlist._frozenlist.FrozenList.append
53 File "frozenlist/_frozenlist.pyx", line 19, in frozenlist._frozenlist.FrozenList._check_frozen
54 raise RuntimeError("Cannot modify frozen list.")
55 RuntimeError: Cannot modify frozen list.
58 FrozenList is also hashable, but only when frozen. Otherwise it also throws a RuntimeError:
61 >>> fl = FrozenList([17, 42, 'spam'])
63 Traceback (most recent call last):
64 File "<stdin>", line 1, in <module>
65 File "frozenlist/_frozenlist.pyx", line 111, in frozenlist._frozenlist.FrozenList.__hash__
66 raise RuntimeError("Cannot hash unfrozen list.")
67 RuntimeError: Cannot hash unfrozen list.
71 >>> dictionary = {fl: 'Vikings'} # frozen fl can be a dict key
73 {<FrozenList(frozen=True, [1, 2])>: 'Vikings'}
81 $ pip install frozenlist
83 The library requires Python 3.6 or newer.
89 https://frozenlist.readthedocs.io/
91 Communication channels
92 ======================
94 *aio-libs discourse group*: https://aio-libs.discourse.group
96 Feel free to post your questions and ideas here.
98 *gitter chat* https://gitter.im/aio-libs/Lobby
108 ``frozenlist`` is offered under the Apache 2 license.
113 The project is hosted on GitHub_
115 Please file an issue in the `bug tracker
116 <https://github.com/aio-libs/frozenlist/issues>`_ if you have found a bug
117 or have some suggestions to improve the library.
119 .. _GitHub: https://github.com/aio-libs/frozenlist