Skip to main content

datahold

Project description

Overview

Wrap common mutable datastructures for inheritance with modification.

Content

BaseList

To understand the class BaseList here the beginning of its code:

class BaseList:

    data: list

    @functools.wraps(list.__add__)
    def __add__(self, *args, **kwargs):
        data = self.data
        ans = data.__add__(*args, **kwargs)
        self.data = data
        return ans

The following methods are defined this way: __add__, __contains__, __delitem__, __eq__, __format__, __ge__, __getitem__, __gt__, __hash__, __iadd__, __imul__, __iter__, __le__, __len__, __lt__, __mul__, __repr__, __reversed__, __rmul__, __setitem__, __str__, append, clear, copy, count, extend, index, insert, pop, remove, reverse, sort

The only function present in list and absent in BaseList is __class_getitem__

We can use BaseList as parent for a list-like class. It is recommended to implement is the subclass: - a property named data with getter and setter wrapping a private variable (for example named _data) - the __init__ magic method This allows the creatation of a list-like class with modified behaviour with only minimal effort. To enhance perpormance we can overwrite some of the methods.

OkayList

This class inherits from BaseList and implements some common sense overwrites for further inheritance. For example:

  • the comparison operations are overwritten:

  • __eq__ returns True iff types are equal and data is equal

  • __ne__ negates __eq__

  • __ge__ returns type(self)(other).__le__(self)

  • __gt__ returns True iff __eq__ returns False and __ge__ returns True

  • __lt__ returns True iff __eq__ returns False and __le__ returns True

  • __le__ returns self.data.__le__(type(self)(other).data)

  • modify __eq__ or __le__ as needed to change the behaviour of the other comparison methods

  • __hash__ raises now a more fitting exception

  • __iadd__ uses now extend

  • __init__ allows now to set data immediately

  • see the code for all overwrites

BaseDict

Just like BaseList but for dict… The following methods are implemented: __contains__, __delitem__, __eq__, __format__, __ge__, __getitem__, __gt__, __hash__, __ior__, __iter__, __le__, __len__, __lt__, __or__, __repr__, __reversed__, __ror__, __setitem__, __str__, clear, copy, get, items, keys, pop, popitem, setdefault, update, values`` The classmethods __class_getitem__ and fromkeys are not implemented.

BaseSet

Just like BaseSet but for set… The following methods are implemented: __and__, __contains__, __eq__, __format__, __ge__, __gt__, __hash__, __iand__, __ior__, __isub__, __iter__, __ixor__, __le__, __len__, __lt__, __or__, __rand__, __repr__, __ror__, __rsub__, __rxor__, __str__, __sub__, __xor__, add, clear, copy, difference, difference_update, discard, intersection, intersection_update, isdisjoint, issubset, issuperset, pop, remove, symmetric_difference, symmetric_difference_update, union, update The classmethod __class_getitem__ is not implemented.

Installation

To install datahold, you can use pip. Open your terminal and run:

pip install datahold

License

This project is licensed under the MIT License.

Credits

Thank you for using datahold!

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

datahold-0.2.27.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

datahold-0.2.27-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file datahold-0.2.27.tar.gz.

File metadata

  • Download URL: datahold-0.2.27.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.4

File hashes

Hashes for datahold-0.2.27.tar.gz
Algorithm Hash digest
SHA256 cc7814fb41bdd664c97ec8117f42b9b0d095a9a8ec4e33b4a1815dfa1b879a57
MD5 59c179ed9e5a164ff7b552ee1be68412
BLAKE2b-256 95bfb7be2fa5177087d825353e6c767b24776bb716cdd5f4f0eb7770236f6846

See more details on using hashes here.

File details

Details for the file datahold-0.2.27-py3-none-any.whl.

File metadata

  • Download URL: datahold-0.2.27-py3-none-any.whl
  • Upload date:
  • Size: 5.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.4

File hashes

Hashes for datahold-0.2.27-py3-none-any.whl
Algorithm Hash digest
SHA256 010420284eb848328bb6f63d0a7e3ef3174adef35fd60fa49c364ae60584254e
MD5 ec9a44b7f5748e270debed5c18226acf
BLAKE2b-256 d3f8997d2724947a89ddce0afde205a0ac2d465a9053c9c368cb8d40c8252e4f

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