Skip to content

patrickboateng/func-validator

Repository files navigation

func-validator

PyPI Latest Release PyPI pyversions license

MATLAB-style function argument validation for Python.

Installation

$ pip install func-validator

Usage

from typing import Annotated
from func_validator import (validate_func_args_at_runtime, 
                            MustBePositive,
                            MustBeNegative)


@validate_func_args_at_runtime
def func(a: Annotated[int, MustBePositive],
         b: Annotated[float, MustBeNegative]):
    pass


func(10, -10)  # ✅ Correct
func(-10, 10)  # ❌ Wrong -10 is not positive and 10 is not negative
func(0, -10)  # ❌ Wrong 0 is not positive

Validators

Numeric Value Validation

MustBePositive Validate that argument value is positive
MustBeNonPositive Validate that argument value is non-positive
MustBeNegative Validate that argument value is negative
MustBeNonNegative Validate that argument value is non-negative

Comparison Validation

MustBeEqual Validate that argument value is equal to another value
MustBeNotEqual Validate that argument value is not equal to another value
MustBeGreaterThan Validate that argument value is greater than another value
MustBeGreaterThanOrEqual Validate that argument value is greater than or equal to another value
MustBeLessThan Validate that argument value is less than another value
MustBeLessThanOrEqual Validate that argument value is less than or equal to another value

Membership Validation

MustBeIn Validate that argument value is in a collection
MustBeBetween Validate that argument value is between two other values

Collection/Iterable Validation

MustBeEmpty Validate that a collection is empty
MustBeNonEmpty Validate that a collection is non-empty
MustHaveLengthEqual Validate that a collection has a specific length
MustHaveLengthGreaterThan Validate that a collection has length greater than a specific value
MustHaveValuesBetween Validate that all values in a collection are between two other values

License

MIT License

About

MATLAB-style function argument validation for Python - clean, simple, and reliable.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages