| 1 |
frozenlist |
| 2 |
========== |
| 3 |
|
| 4 |
.. image:: https://github.com/aio-libs/frozenlist/workflows/CI/badge.svg |
| 5 |
:target: https://github.com/aio-libs/frozenlist/actions |
| 6 |
:alt: GitHub status for master branch |
| 7 |
|
| 8 |
.. image:: https://codecov.io/gh/aio-libs/frozenlist/branch/master/graph/badge.svg?flag=pytest |
| 9 |
:target: https://codecov.io/gh/aio-libs/frozenlist?flags[]=pytest |
| 10 |
:alt: codecov.io status for master branch |
| 11 |
|
| 12 |
.. image:: https://img.shields.io/pypi/v/frozenlist.svg?logo=Python&logoColor=white |
| 13 |
:target: https://pypi.org/project/frozenlist |
| 14 |
:alt: frozenlist @ PyPI |
| 15 |
|
| 16 |
.. image:: https://readthedocs.org/projects/frozenlist/badge/?version=latest |
| 17 |
:target: https://frozenlist.aio-libs.org |
| 18 |
:alt: Read The Docs build status badge |
| 19 |
|
| 20 |
.. image:: https://img.shields.io/matrix/aio-libs:matrix.org?label=Discuss%20on%20Matrix%20at%20%23aio-libs%3Amatrix.org&logo=matrix&server_fqdn=matrix.org&style=flat |
| 21 |
:target: https://matrix.to/#/%23aio-libs:matrix.org |
| 22 |
:alt: Matrix Room — #aio-libs:matrix.org |
| 23 |
|
| 24 |
.. image:: https://img.shields.io/matrix/aio-libs-space:matrix.org?label=Discuss%20on%20Matrix%20at%20%23aio-libs-space%3Amatrix.org&logo=matrix&server_fqdn=matrix.org&style=flat |
| 25 |
:target: https://matrix.to/#/%23aio-libs-space:matrix.org |
| 26 |
:alt: Matrix Space — #aio-libs-space:matrix.org |
| 27 |
|
| 28 |
Introduction |
| 29 |
------------ |
| 30 |
|
| 31 |
``frozenlist.FrozenList`` is a list-like structure which implements |
| 32 |
``collections.abc.MutableSequence``. The list is *mutable* until ``FrozenList.freeze`` |
| 33 |
is called, after which list modifications raise ``RuntimeError``: |
| 34 |
|
| 35 |
|
| 36 |
>>> from frozenlist import FrozenList |
| 37 |
>>> fl = FrozenList([17, 42]) |
| 38 |
>>> fl.append('spam') |
| 39 |
>>> fl.append('Vikings') |
| 40 |
>>> fl |
| 41 |
<FrozenList(frozen=False, [17, 42, 'spam', 'Vikings'])> |
| 42 |
>>> fl.freeze() |
| 43 |
>>> fl |
| 44 |
<FrozenList(frozen=True, [17, 42, 'spam', 'Vikings'])> |
| 45 |
>>> fl.frozen |
| 46 |
True |
| 47 |
>>> fl.append("Monty") |
| 48 |
Traceback (most recent call last): |
| 49 |
File "<stdin>", line 1, in <module> |
| 50 |
File "frozenlist/_frozenlist.pyx", line 97, in frozenlist._frozenlist.FrozenList.append |
| 51 |
self._check_frozen() |
| 52 |
File "frozenlist/_frozenlist.pyx", line 19, in frozenlist._frozenlist.FrozenList._check_frozen |
| 53 |
raise RuntimeError("Cannot modify frozen list.") |
| 54 |
RuntimeError: Cannot modify frozen list. |
| 55 |
|
| 56 |
|
| 57 |
FrozenList is also hashable, but only when frozen. Otherwise it also throws a RuntimeError: |
| 58 |
|
| 59 |
|
| 60 |
>>> fl = FrozenList([17, 42, 'spam']) |
| 61 |
>>> hash(fl) |
| 62 |
Traceback (most recent call last): |
| 63 |
File "<stdin>", line 1, in <module> |
| 64 |
File "frozenlist/_frozenlist.pyx", line 111, in frozenlist._frozenlist.FrozenList.__hash__ |
| 65 |
raise RuntimeError("Cannot hash unfrozen list.") |
| 66 |
RuntimeError: Cannot hash unfrozen list. |
| 67 |
>>> fl.freeze() |
| 68 |
>>> hash(fl) |
| 69 |
3713081631934410656 |
| 70 |
>>> dictionary = {fl: 'Vikings'} # frozen fl can be a dict key |
| 71 |
>>> dictionary |
| 72 |
{<FrozenList(frozen=True, [1, 2])>: 'Vikings'} |
| 73 |
|
| 74 |
|
| 75 |
Installation |
| 76 |
------------ |
| 77 |
|
| 78 |
:: |
| 79 |
|
| 80 |
$ pip install frozenlist |
| 81 |
|
| 82 |
|
| 83 |
Documentation |
| 84 |
------------- |
| 85 |
|
| 86 |
https://frozenlist.aio-libs.org |
| 87 |
|
| 88 |
Communication channels |
| 89 |
---------------------- |
| 90 |
|
| 91 |
We have a *Matrix Space* `#aio-libs-space:matrix.org |
| 92 |
<https://matrix.to/#/%23aio-libs-space:matrix.org>`_ which is |
| 93 |
also accessible via Gitter. |
| 94 |
|
| 95 |
License |
| 96 |
------- |
| 97 |
|
| 98 |
``frozenlist`` is offered under the Apache 2 license. |
| 99 |
|
| 100 |
Source code |
| 101 |
----------- |
| 102 |
|
| 103 |
The project is hosted on GitHub_ |
| 104 |
|
| 105 |
Please file an issue in the `bug tracker |
| 106 |
<https://github.com/aio-libs/frozenlist/issues>`_ if you have found a bug |
| 107 |
or have some suggestions to improve the library. |
| 108 |
|
| 109 |
.. _GitHub: https://github.com/aio-libs/frozenlist |