Skip to main content

Support for requirements-assisted development

Project description

Decorate an instance method with pre- and/or postconditions that must be fulfilled

Example usage

from requiresthat import requires, RequirementNotFulfilledError, APRIORI, POSTMORTEM, BEFOREANDAFTER

class C:

    def __init__(self, data=None):
        self.data = data

    @requires(that='self.data is not None')
    @requires(that='self.data == "spam"', when=APRIORI)
    @requires(that='True is not False')
    @requires(that='self.data != "spam"', when=POSTMORTEM)
    @requires(that='len(self.data) >= 3', when=BEFOREANDAFTER)
    def method(self):
        self.data = 'ham'

X = C(data='spam')
X.method()

The that can be almost any valid Python statement which can be evaluated and whose veracity can be asserted, and the result thereof will decide whether or not the method fires/will be considered a success.

The parameter when decides if the condition is a-priori, post-mortem, or before-and-after. The default is a-priori, meaning a precondition. Note that before-and-after does not mean during; you cannot mandate an invariant this way!

RequirementNotFulfilledError is the exception you have to deal with in case a condition is not met. NoCallableConstructError gets raised should you apply the decorator to a construct that is not callable.

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

requiresthat-2025.6.18.2.tar.gz (3.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

requiresthat-2025.6.18.2-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

Details for the file requiresthat-2025.6.18.2.tar.gz.

File metadata

  • Download URL: requiresthat-2025.6.18.2.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for requiresthat-2025.6.18.2.tar.gz
Algorithm Hash digest
SHA256 4ef3d17e160e7379ba4397a137e6af3a10e77772295f2d1b4c44324c15b7148a
MD5 25baa879dfbd17391aa359b36c27f4b6
BLAKE2b-256 0c3115da5c50447bc63b823eeba7c1115e7b209be2fa10e53e5a68fe4d866d46

See more details on using hashes here.

File details

Details for the file requiresthat-2025.6.18.2-py3-none-any.whl.

File metadata

File hashes

Hashes for requiresthat-2025.6.18.2-py3-none-any.whl
Algorithm Hash digest
SHA256 dd351827740e4d1657e07ee6e6f307a5fd7d6bdccb7b0d6595d25d57d1054fde
MD5 ef3a47b4e433f30c9d251fd9aeff5faf
BLAKE2b-256 df95788ca7a986d21e6708de0a25956a467e518621dd94ea40f1073e743efaba

See more details on using hashes here.

Supported by

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