Skip to main content

A Set implementation that tracks added and removed elements.

Project description

A Set implementation that tracks added and removed elements.

Usage

>>> from history_set import HistorySet
>>> history_set = HistorySet([1, 2, 3])
>>> history_set.add(4)
>>> history_set                   # Prints: {1, 2, 3, 4}
>>> history_set.added()           # Prints: {4}
>>> history_set.remove(1)
>>> history_set                   # Prints: {2, 3, 4}
>>> history_set.removed()         # Prints: {1}
>>> history_set.reset()
>>> history_set.added()           # Prints: set()
>>> history_set.removed()         # Prints: set()

Special case

By default, if an element is added and later removed, it will not be tracked in history

>>> history_set = HistorySet([1, 2, 3])
>>> history_set.add(4)
>>> history_set.remove(4)
>>> history_set.added()           # Prints: set()
>>> history_set.removed()         # Prints: set()

If you require these elements to be tracked, you can construct the object with the eidetic keyword argument

>>> history_set = HistorySet([1, 2, 3], eidetic=True)
>>> history_set.add(4)
>>> history_set.remove(4)
>>> history_set.added()           # Prints: {4}
>>> history_set.removed()         # Prints: {4}

By default, the reset() method will clear the entire history

>>> history_set = HistorySet([1, 2, 3])
>>> history_set.add(4)
>>> history_set.added()           # Prints: {4}
>>> history_set.remove(2)
>>> history_set.removed()         # Prints: {2}
>>> history_set.reset()
>>> history_set.added()           # Prints: set()
>>> history_set.removed()         # Prints: set()

If you require reseting only the added() or removed() history, you can call the reset method with added or removed booleans values to specify which history you with to reset

>>> history_set = HistorySet([1, 2, 3])
>>> history_set.add(4)
>>> history_set.added()           # Prints: {4}
>>> history_set.remove(2)
>>> history_set.removed()         # Prints: {2}
>>> history_set.reset(added=True)
>>> history_set.added()           # Prints: set()
>>> history_set.removed()         # Prints: {2}

Test

You can run the tests using tox

tox

Publish

To publish a new version of this package your Pypi user needt to be added to the project. (Ask Tjaart to give you access)

# Update version number in setup.py

python setup.py sdist
twine upload dist/*

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

history-set-0.1.3.tar.gz (2.4 kB view details)

Uploaded Source

File details

Details for the file history-set-0.1.3.tar.gz.

File metadata

File hashes

Hashes for history-set-0.1.3.tar.gz
Algorithm Hash digest
SHA256 7df5d763c3e6f8dcfc8aaed3f61ecbde463a2e2dcc8c13faa11bef9891cfc2f6
MD5 ea7a28540e39e4bbfecdc167184e29d3
BLAKE2b-256 79973809c5fba3c62bf23e2b9beb5d9ace8d7b458753c7e5c26f3611d8e525f9

See more details on using hashes here.

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