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 hashes)
Built Distribution
frz-0.0.2-py3-none-any.whl
(4.3 kB
view hashes)