Frozen implementations of your favorite collections.
Project description
Freeze
Freeze introduces 3 frozen collections: FDict
, FSet
and FList
.
They are immutable, hashable, support type-hinting, and will attempt to recursively convert mutable
collections into frozen counterparts on initialization.
Motivation
While there are built-in immutable versions for list (tuple) and set (frozenset), they have some issues:
- tuple can store mutable objects so its immutability is not guaranteed.
- frozenset can't be initialized with mutable objects.
- dict doesn't have a built-in immutable version at all.
Installation
pip install frz
Usage
from freeze import FDict, FList, FSet
a_mutable_dict = {
"list": [1, 2],
"set": {3, 4},
}
a_frozen_dict = FDict(a_mutable_dict)
print(repr(a_frozen_dict)) # FDict: {'list': FList: (1, 2), 'set': FSet: {3, 4}}
How Freeze Works
Freezing a collection is achieved by following the following logic recursively:
- Immutable objects (except for collections) stay the same.
- Mapping (e.g. dict) frozen with FDict.
- Sequence (e.g. list or tuple) frozen as FLists.
- AbstractSet (e.g. set) frozen as FSets.
- If any value in the collection can't be frozen, an exception is raised.
Known Issues:
- Type hints are only accurate as long as no data conversion was performed.
Future Plans:
- support for thawing frozen collections.
- support for freezing more mutable types.
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
frz-0.0.2.tar.gz
(3.9 kB
view details)
Built Distribution
frz-0.0.2-py3-none-any.whl
(4.3 kB
view details)
File details
Details for the file frz-0.0.2.tar.gz
.
File metadata
- Download URL: frz-0.0.2.tar.gz
- Upload date:
- Size: 3.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.1 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ea2fd3267da39b03afbd4d5011c212a025e6a328d55b3164bca51c5edc196892 |
|
MD5 | c4cf7c6f98b3bbf4994b03b2980f64eb |
|
BLAKE2b-256 | 8f39338f834eba3a7a949b8b12c0e4af7b2328fb7bc35f144f4a01f02a16f348 |
File details
Details for the file frz-0.0.2-py3-none-any.whl
.
File metadata
- Download URL: frz-0.0.2-py3-none-any.whl
- Upload date:
- Size: 4.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.1 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6ba9e18cf99f5980bb47885bf6fbf8d14b3bb5c0fb87515318b0115b3361b9fd |
|
MD5 | 700186409d6e26ccd2dd9e44ade2013f |
|
BLAKE2b-256 | ae624895387b4bfdd645e3d2f6a449a4243c0b8f6411b06fa727298be0fd304e |