Skip to main content

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

Project description

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

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

func_validator-0.9.0.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

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

func_validator-0.9.0-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file func_validator-0.9.0.tar.gz.

File metadata

  • Download URL: func_validator-0.9.0.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for func_validator-0.9.0.tar.gz
Algorithm Hash digest
SHA256 1f8925941d750061fc358b4dbfd5c3c532cec9ae5c7acdca7a2a2f2182d54715
MD5 6deffb8f65f53381bfb08e5ef4c17eab
BLAKE2b-256 dcdffbcb29810f22a00c424fd86148c3b04f9242e86c7df71dd238a2dcfda90f

See more details on using hashes here.

Provenance

The following attestation bundles were made for func_validator-0.9.0.tar.gz:

Publisher: func-validator-publish.yml on patrickboateng/func-validator

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file func_validator-0.9.0-py3-none-any.whl.

File metadata

  • Download URL: func_validator-0.9.0-py3-none-any.whl
  • Upload date:
  • Size: 5.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for func_validator-0.9.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2b7705deea2b0caaa88311f50622ae27c17a53c28073680e2d341f90e3231c23
MD5 385274d5634dad2c98ea12f409e89337
BLAKE2b-256 3cea4f95757f6b981b17eae0ac2dd6cde0965f0497218e4360290ee13a39ee32

See more details on using hashes here.

Provenance

The following attestation bundles were made for func_validator-0.9.0-py3-none-any.whl:

Publisher: func-validator-publish.yml on patrickboateng/func-validator

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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