A powerful, expressive and lightweight design-by-contract framework
Project description
ContractMe
A lightweight and adaptable framework for design-by-contract in python
Example code
Here are some examples:
result
@precondition(lambda x: x >= 0)
@postcondition(lambda x, result: eps_eq(result * result, x))
def square_root(x: float) -> float:
return x**0.5
old
@precondition(lambda l, n: n >= 0 and round(n) == n)
@postcondition(lambda l, n: len(l) > 0)
@postcondition(lambda l, n: l[-1] == n)
@postcondition(lambda l, n, old: l[:-1] == old.l)
def append_count(l: list[int], n: int):
l.append(n)
Test
uv run pytest
Changelog
- v1.1.0
Contracts can be disabled at runtime with ignore_preconditions() and ignore_postconditions()
Contracts are disabled from the start with python optimized (-O) flag.
Fix a bug where contracts would hide an incorrect function call
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file contractme-1.1.0.tar.gz.
File metadata
- Download URL: contractme-1.1.0.tar.gz
- Upload date:
- Size: 13.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1a87c5cc8053bc1c1b7f4d3005e1b8504c41e506dbe9e2aee4c9cf8f329cbeb9
|
|
| MD5 |
4422be15f7a80da1ce06aca3c2ab1ba0
|
|
| BLAKE2b-256 |
2e231f283721583540269cae06843f9dcf8c923a081f632aaaa8b1618a094459
|
File details
Details for the file contractme-1.1.0-py3-none-any.whl.
File metadata
- Download URL: contractme-1.1.0-py3-none-any.whl
- Upload date:
- Size: 8.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5d08d81886ac5b1dc32f79e1dec4d86d42ef21c85939ad579d1c4db9b7cd2035
|
|
| MD5 |
9cb81185f6af9a14a6f6c0fcf4b5be71
|
|
| BLAKE2b-256 |
b52e917c7cfd45e4d0fdb2c55d39726a244f53e0f30a04fb16be5740cf1d9a5a
|