Freezable: Dynamically Immutable Objects
NOTICE: This project is in Alpha; you may encounter bugs.
Freezable is a package that allows you to implement "freezable" types in Python, which can either be "frozen" or "unfrozen." When frozen, all operations and methods that mutate the object are disabled.
Here is an example of a "freezable" stack and its usage:
from freezable import Freezable, FrozenError, enabled_when_unfrozen
class FreezableStack(Freezable):
def __init__(self):
self._data = [] # data of the stack
@enabled_when_unfrozen
def push(self, x): # pushes to the top of stack
self._data.append(x)
def top(self): # returns top of stack, if any
return self._data[-1] if self._data else None
# We can use the stack as normal.
stk = FreezableStack()
assert stk.top() is None
stk.push(1)
assert stk.top() == 1
stk.push(2)
assert stk.top() == 2
# Once we freeze it, all mutating methods/operations are disabled.
stk.freeze()
try:
stk.push(3) # error because stk is frozen
except FrozenError:
pass
assert stk.top() == 2 # push did not happen
# We can unfreeze it to use the stack mutably again.
stk.unfreeze()
stk.push(3)
assert stk.top() == 3
This package can be useful in finding logical errors in which objects are mutated when they are not supposed to.
Links
Documentation @ReadTheDocs (on most recent stable release)
Installation
This package can be installed using Pip:
pip install freezable
Bug Reports and Feature Requests
You can report a bug or suggest a feature on the Github repo.
Contributions
Contributions to this project are welcome. :)
See the pull requests page on Github.
Metadata
Release files for freezable 0.1.9
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| freezable-0.1.9.tar.gz | 5.2 kB | Without provenance | Details for freezable-0.1.9.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| freezable-0.1.9-py3-none-any.whl | Python 3 | none | any | Details for freezable-0.1.9-py3-none-any.whl |
Total release size: 10.2 kB
Release files / freezable-0.1.9.tar.gz
| Download URL | freezable-0.1.9.tar.gz |
|---|---|
| Size | 5.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
13142b3ae4f46b71435d64fa0daa9c8f6906373afea0a681e2d82fd6aed3e726
|
|
BLAKE2b-256 checksum How to use checksums |
2f8ef5055017152e823535ff714f82ef5c70049bad2b93d98918d40664c3d3ba
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.13 CPython/3.10.0 Windows/10
|
Release files / freezable-0.1.9-py3-none-any.whl
| Download URL | freezable-0.1.9-py3-none-any.whl |
|---|---|
| Size | 5.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
adc65bbb0b24775db16c6f45e9757736a459bcf63522283ab367d01e54537523
|
|
BLAKE2b-256 checksum How to use checksums |
9bb8452b0f265bc5a92ea7897cd7cd734bf9669a2f8ee1a993982f33791ade42
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.13 CPython/3.10.0 Windows/10
|
Security for freezable 0.1.9
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.