MATLAB-style function argument validation for Python.
$ pip install func-validator
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
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 |
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 |
MustBeIn | Validate that argument value is in a collection |
MustBeBetween | Validate that argument value is between two other values |
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 |
MIT License