Skip to main content

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_types for 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_types validates function arguments only.
  • Return annotations are not enforced.
  • Errors raise TypeError or ValueError depending 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)

Uploaded Source

Built Distribution

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

prerequisites-1.0.5-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

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

Hashes for prerequisites-1.0.5.tar.gz
Algorithm Hash digest
SHA256 54461b7e3a40822ac6b122eed7848c8dcfd19f7c8bf862e197df6ec51441c9a6
MD5 0e0a09f0fb24b94ebd59b3ad062806fd
BLAKE2b-256 f17e5b5d48fc398601fcd954c66e26a2a5961fdd9ebd91eea2875051b31891e0

See more details on using hashes here.

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

Hashes for prerequisites-1.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 e9c7ba595ef90312e71f33c864d1f804e9d96c442713c9c7991bf55047a681fb
MD5 9f9c0cae7b3c5275c386ccf23289e3d6
BLAKE2b-256 d4ae56a5f332058c0dc5f9f876e9ba3257e3a0b1fc3f1a015e1c902d80357792

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