object-freezer
Python module for freezing objects.
Installation
$ pip install object-freezer
Then import this module as:
import object_freezer as of
Examples
A list is frozen into a tuple:
>>> l = [1, 2, 3]
>>> hash(l)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unhashable type: 'list'
>>> fl = of.freeze(l)
>>> hash(fl)
2528502973977326415
>>> fl
(1, 2, 3)
A dictionary is frozen into a deepfrozendict instance:
>>> import object_freezer as of
>>> d = {'a': 'A', 'b': 'B'}
>>> hash(d)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unhashable type: 'dict'
>>> fd = of.freeze(d)
>>> hash(fd)
3871628092596788623
>>> fd
<deepfrozendict {'a': 'A', 'b': 'B'}>
If an element of a list is not hashable, it will also be frozen:
>>> l = [[1, 2], {3: 4}]
>>> hash(l)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unhashable type: 'list'
>>> fl = of.freeze(l)
>>> hash(fl)
5879964472677921951
>>> fl
((1, 2), <deepfrozendict {3: 4}>)
If a value of a dictionary is not hashable, it will be frozen:
>>> import object_freezer as of
>>> d = {'a': ['A', 0], 'b': {'B': 1}}
>>> hash(d)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unhashable type: 'dict'
>>> fd = of.freeze(d)
>>> hash(fd)
6230706721132225338
>>> fd
<deepfrozendict {'a': ('A', 0), 'b': <deepfrozendict {'B': 1}>}>
Known issues & notes
A dict with one (key, value) pair has the same hash value as a tuple (key, value)
Since a list is frozen into a tuple, it is obvious that of.freeze([key, value]) and of.freeze((key, value)) are the same and thus have the same hash value. However, of.freeze({key: value}) also always has the same hash value.
>>> d = {1: 2}
>>> t = (1, 2)
>>> fd = of.freeze(d)
>>> ft = of.freeze(t)
>>> hash(fd) == hash(ft)
True
It is not a major issue since fd == ft returns False. Therefore, for example, you can use fd and ft as a distinct dictionary keys.
>>> fd == ft
False
>>> {fd: 0, ft: 1}
{<deepfrozendict {1: 2}>: 0, (1, 2): 1}
License
TO-DO's
- Test against various Python versions.
Metadata
Release files for object-freezer 0.1.2
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 | |
|---|---|---|---|---|
| object-freezer-0.1.2.tar.gz | 5.2 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| object_freezer-0.1.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 10.7 kB
Release files / object-freezer-0.1.2.tar.gz
| Download URL | object-freezer-0.1.2.tar.gz |
|---|---|
| Size | 5.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e15afab7577a795a98f201b15531e74aad6dcd51935bcc251db68281cd7dd76c
|
|
BLAKE2b-256 checksum How to use checksums |
b58fefbb074e664a0e05d4b298bf3125667ff163b3655e6ce0089441bc2e5bb6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5
|
Release files / object_freezer-0.1.2-py3-none-any.whl
| Download URL | object_freezer-0.1.2-py3-none-any.whl |
|---|---|
| Size | 5.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1c7aa9dace338fa48f11f97a24339f2f55a862d29e6906c64a99ad845bc33a9c
|
|
BLAKE2b-256 checksum How to use checksums |
31814be60258baf3929910347c566bac57cdf85060752e20c9d88bc3f4632958
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5
|
Security for object-freezer 0.1.2
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.