Prerequisite functions to help and assert inputs and outputs condition and type
Project description
prerequisites
Small runtime validation helpers for preconditions and type checks.
Install
pip install prerequisites
What it provides
- Value checks:
require,require_one_in_all,require_all_in_all - Type checks:
require_type,require_one_of_types,require_all_of_type,require_all_same_type,require_type_or_none - Decorator checks:
@validate_typesfor argument validation using type hints
Quick examples
Value checks
from prerequisites import require, require_all_in_all, require_one_in_all
require(2 > 1)
require_one_in_all([False, True, False])
require_all_in_all([True, 2 + 2 == 4])
Type checks
from prerequisites import (
require_all_of_type,
require_all_same_type,
require_one_of_types,
require_type,
require_type_or_none,
)
require_type(10, int)
require_one_of_types(3.14, (int, float))
require_all_of_type([1, 2, 3], int)
require_all_same_type(["a", "b", "c"], (str,))
require_type_or_none(None, str)
Decorator validation
from prerequisites import validate_types
@validate_types
def add(a: int, b: int) -> int:
return a + b
add(1, 2) # ok
add("1", 2) # raises TypeError
Shallow container behavior
@validate_types validates only outer container types for parameterized hints.
from prerequisites import validate_types
@validate_types
def count(values: list[int]) -> int:
return len(values)
count([1, 2, 3])
count([1, "x"]) # valid in current shallow mode (still a list)
Notes
@validate_typesvalidates function arguments only.- Return annotations are not enforced.
- Errors raise
TypeErrororValueErrordepending on the helper.
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
prerequisites-1.0.5.tar.gz
(43.4 kB
view details)
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 prerequisites-1.0.5.tar.gz.
File metadata
- Download URL: prerequisites-1.0.5.tar.gz
- Upload date:
- Size: 43.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
54461b7e3a40822ac6b122eed7848c8dcfd19f7c8bf862e197df6ec51441c9a6
|
|
| MD5 |
0e0a09f0fb24b94ebd59b3ad062806fd
|
|
| BLAKE2b-256 |
f17e5b5d48fc398601fcd954c66e26a2a5961fdd9ebd91eea2875051b31891e0
|
File details
Details for the file prerequisites-1.0.5-py3-none-any.whl.
File metadata
- Download URL: prerequisites-1.0.5-py3-none-any.whl
- Upload date:
- Size: 6.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e9c7ba595ef90312e71f33c864d1f804e9d96c442713c9c7991bf55047a681fb
|
|
| MD5 |
9f9c0cae7b3c5275c386ccf23289e3d6
|
|
| BLAKE2b-256 |
d4ae56a5f332058c0dc5f9f876e9ba3257e3a0b1fc3f1a015e1c902d80357792
|