Skip to main content

Accretive data structures.

Project description

Project Version PyPI - Status Tests Status Code Coverage Percentage Python Versions Project License

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

GitHub last commit Hatch pre-commit Bandit Mypy Pylint Ruff PyPI - Implementation PyPI - Wheel

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

accretive-2.0.tar.gz (18.0 kB view details)

Uploaded Source

Built Distribution

accretive-2.0-py3-none-any.whl (25.1 kB view details)

Uploaded Python 3

File details

Details for the file accretive-2.0.tar.gz.

File metadata

  • Download URL: accretive-2.0.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

Hashes for accretive-2.0.tar.gz
Algorithm Hash digest
SHA256 d70592b414ab47ab95626fed8c812700929006a28e77f1dfbf9a6f9420154e0f
MD5 3fd67a8292f8cd0d5c434fd3bdaf8680
BLAKE2b-256 86fdde18d433200a709c1eae970d55401f69eb0358582441ad31f98a5e1c14c5

See more details on using hashes here.

Provenance

The following attestation bundles were made for accretive-2.0.tar.gz:

Publisher: releaser.yaml on emcd/python-accretive

Attestations:

File details

Details for the file accretive-2.0-py3-none-any.whl.

File metadata

  • Download URL: accretive-2.0-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

Hashes for accretive-2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fc03b0514320cb0f5d96b1c75270a95afa9256e77586c46035c1ee07174dd436
MD5 25d348ad8682a7a50f2506e20b16197d
BLAKE2b-256 ba3f9458a9d9ebb348b36a8159b00e29252a8ea1b844e9cf4087a4a8caa6d1a0

See more details on using hashes here.

Provenance

The following attestation bundles were made for accretive-2.0-py3-none-any.whl:

Publisher: releaser.yaml on emcd/python-accretive

Attestations:

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page