Accretive data structures.
Project description
A Python library package which provides accretive data structures.
Accretive data structures can grow at any time but can never shrink. An accretive dictionary accepts new entries, but cannot have existing entries altered or removed. Similarly, an accretive namespace accepts new attributes, but cannot have existing attributes assigned to new values or deleted.
Accretive data structures are useful as registries, which may be incrementally initialized, but should have immutable state, once initialized. In general, they are a good compromise between the safety of immutability and the convenience of incremental initialization.
In addition to accretive dictionaries (including dictionaries with default entries) and namespaces, this package also provides accretive classes (including abstract base classes), modules, and objects. Subpackages provide variants of all of these with some additional behaviors or constraints. Modules of aliases are also provided to satisfy various import styles and nomenclatural conventions.
Examples
Accretive Namespace
An accretive namespace, similar to types.SimpleNamespace, is available. This namespace can be initialized from multiple iterables and from keyword arguments. (Keyword arguments shown below; see documentation for additional forms of initialization.)
>>> from accretive import Namespace >>> ns = Namespace( apples = 12, bananas = 6, cherries = 42 ) >>> ns accretive.namespaces.Namespace( apples = 12, bananas = 6, cherries = 42 )
Arbitrary attributes can be assigned, as is expected in Python.
>>> ns.blueberries = 96 >>> ns.strawberries = 24 >>> ns accretive.namespaces.Namespace( apples = 12, bananas = 6, cherries = 42, blueberries = 96, strawberries = 24 )
Since the namespace is accretive, attributes cannot be deleted.
>>> del ns.apples Traceback (most recent call last): ... accretive.exceptions.IndelibleAttributeError: Cannot reassign or delete existing attribute 'apples'.
Or reassigned.
>>> ns.apples = 14 Traceback (most recent call last): ... accretive.exceptions.IndelibleAttributeError: Cannot reassign or delete existing attribute 'apples'.
The attributes thus retain their original values.
>>> ns accretive.namespaces.Namespace( apples = 12, bananas = 6, cherries = 42, blueberries = 96, strawberries = 24 )
Accretive Dictionary
An accretive dictionary, similar to dict, is available. This dictionary can be initialized from multiple iterables and from keyword arguments. (Keyword arguments shown below; see documentation for additional forms of initialization.)
>>> from accretive import Dictionary >>> dct = Dictionary( apples = 12, bananas = 6, cherries = 42 ) >>> dct accretive.dictionaries.Dictionary( {'apples': 12, 'bananas': 6, 'cherries': 42} )
Entries can be added to the dictionary after initialization. This includes via a batch operation, such as update, which can accept the same forms of arguments as dictionary initialization.
>>> dct.update( blueberries = 96, strawberries = 24 ) accretive.dictionaries.Dictionary( {'apples': 12, 'bananas': 6, 'cherries': 42, 'blueberries': 96, 'strawberries': 24} )
Since the dictionary is accretive, existing entries cannot be removed.
>>> del dct[ 'bananas' ] Traceback (most recent call last): ... accretive.exceptions.IndelibleEntryError: Cannot update or remove existing entry for 'bananas'.
Or altered.
>>> dct[ 'bananas' ] = 11 Traceback (most recent call last): ... accretive.exceptions.IndelibleEntryError: Cannot update or remove existing entry for 'bananas'.
The entries thus remain unchanged.
>>> dct accretive.dictionaries.Dictionary( {'apples': 12, 'bananas': 6, 'cherries': 42, 'blueberries': 96, 'strawberries': 24} )
Installation
pip install accretive
More Flair
…than the required minimum
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
File details
Details for the file accretive-2.1a0.tar.gz
.
File metadata
- Download URL: accretive-2.1a0.tar.gz
- Upload date:
- Size: 18.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2d90242a362d4eda0be877fd90d7519169c4ca68c8df0e2827d12c58855a27d1 |
|
MD5 | 2349dc4670c19ec1f7429f529566b638 |
|
BLAKE2b-256 | 8aa5736e180c55bc8dc88026b3330f53d06432b2dbf97083583fd6c3cbacf5b0 |
Provenance
The following attestation bundles were made for accretive-2.1a0.tar.gz
:
Publisher:
releaser.yaml
on emcd/python-accretive
-
Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
accretive-2.1a0.tar.gz
- Subject digest:
2d90242a362d4eda0be877fd90d7519169c4ca68c8df0e2827d12c58855a27d1
- Sigstore transparency entry: 147990832
- Sigstore integration time:
- Predicate type:
File details
Details for the file accretive-2.1a0-py3-none-any.whl
.
File metadata
- Download URL: accretive-2.1a0-py3-none-any.whl
- Upload date:
- Size: 25.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 92a2f0fb7277722014a62a6f48c15005f77ae18c27da7885f3683e711bd74196 |
|
MD5 | d487bdfe0913a8e0ad4a508553f95380 |
|
BLAKE2b-256 | 41cbe6e63190de4c8ca092e959ac795911ddf832b882f888bc1dba092770c230 |
Provenance
The following attestation bundles were made for accretive-2.1a0-py3-none-any.whl
:
Publisher:
releaser.yaml
on emcd/python-accretive
-
Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
accretive-2.1a0-py3-none-any.whl
- Subject digest:
92a2f0fb7277722014a62a6f48c15005f77ae18c27da7885f3683e711bd74196
- Sigstore transparency entry: 147990834
- Sigstore integration time:
- Predicate type: