Dynamically immutable objects
Project description
Freezable: Dynamically Immutable Objects
NOTICE: This project is in Alpha; expect bugs! API is also subject to change.
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 one example:
from freezable import Freezable, FrozenError, enabled_when_unfrozen
class FreezableStack(Freezable):
def __init__(self):
self._data = []
@enabled_when_unfrozen
def push(self, x):
self._data.append(x)
def top(self):
return self._data[-1] if self._data else None
stk = FreezableStack()
assert stk.top() is None
stk.push(1)
assert stk.top() == 1
stk.push(2)
assert stk.top() == 2
stk.freeze()
try:
stk.push(3) # error because stk is frozen
except FrozenError:
pass
assert stk.top() == 2 # operation did not proceed
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.
See the documentation for more information on how to use this project.
Links
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.
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
Built Distribution
Hashes for freezable-0.1.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 753cc35b148d98e642aae7332c55ac3366f8858db6ae30e17dce15b30d29938a |
|
MD5 | 7f1f097dc05df85c801e8b61b2273086 |
|
BLAKE2b-256 | 2a7844893f7155aa395762b0a427f7f90a496c5b34b4ba327f0b0fc92ccca444 |