Skip to main content

datahold

Project description

Overview

Wrap common 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 functions are defined the same way: __contains__, __delitem__, __eq__, __format__, __ge__, __getitem__, __gt__, __hash__, __iadd__, __imul__, __iter__, __le__, __len__, __lt__, __mul__, __reduce__, __reduce_ex__, __repr__, __reversed__, __rmul__, __setitem__, __str__, append, clear, copy, count, extend, index, insert, pop, remove, reverse, sort

The only function preset 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: * __hash__ raises now a more fitting exception * __iadd__ uses now extend * __init__ allows now to set data immediately * 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

  • see the code for all overwrites

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.9.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

datahold-0.2.9-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: datahold-0.2.9.tar.gz
  • Upload date:
  • Size: 4.0 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.9.tar.gz
Algorithm Hash digest
SHA256 833642e873dc6e9ab6abb7982de3ce4b56cc54d4fe3ad8c35a2bea2f04ed0990
MD5 fa6d64f9e8349f2719138bf6e0f01db1
BLAKE2b-256 21cbf81e2a1bc330eeea3359b54e19f8578519a92cd85ad86892cb538c10663d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: datahold-0.2.9-py3-none-any.whl
  • Upload date:
  • Size: 4.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.9-py3-none-any.whl
Algorithm Hash digest
SHA256 fe7e61d951d1dd7265c52a1e7502fb82d65a1077b2aa5c5e4c7d0a102e62ed3d
MD5 2b63078a201711f87d032944c4a8d0cc
BLAKE2b-256 4b94cf082275eb57def804af7e451a7ce012e0fb03bc3e1af7dc7db1bed7475b

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