No project description provided
Project description
frozenset is to set as freeze is to Any.
That is, type(a) is type(b) and a != b implies freeze(a) != freeze(b).
Moreover, this function is deterministic, so it can be used to compare states across subsequent process invocations.
>>> obj = [1, 2, 3, {4, 5, 6}, object()] >>> hash(obj) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: unhashable type: 'list'
>>> from charmonium.freeze import freeze >>> frozen_obj = freeze(obj) >>> frozen_obj (1, 2, 3, frozenset({4, 5, 6}), ("<class 'type'>", ('object',))) >>> hash(frozen_obj) % 1 0
Special cases
freeze on functions returns their bytecode, constants, and closure-vars. This means that freeze_state(f) == freeze_state(g) implies f(x) == g(x). The remarkable thing is that this is true across subsequent invocations of the same process. If the user edits the script and changes the function, then it’s freeze_state will change too.
freeze on objects returns the objects that would be used by pickle from __reduce__, __reduce_ex__, __getnewargs__, __getnewargs_ex__, and __getstate__. The simplest of these to customize your object __gestate__. See the pickle documentation for details.
In the cases where __getstate__ is already defined for pickle, and this definition is not suitable for freeze_state, one may override this with __getfrozenstate__ which takes precedence.
Although, this function is not infallible for user-defined types; I will do my best, but sometimes these laws will be violated. These cases include:
Cases where __eq__ makes objects equal despite differing attributes or inversely make objects inequal despite equal attributes.
This can be mitigated if __getstate__ or __getfrozenstate__
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 charmonium.freeze-0.2.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fbd22f3b1458eb71c2d940db1dd85e16bb65ac24e07e0c0223f565ef35c21c96 |
|
MD5 | abfcfd934bb30e7ad838ff7e360d0865 |
|
BLAKE2b-256 | 9183877da731d458ed59ab174254753b1948a0a63bc3a93d979bbd4f393adf9c |