Skip to main content

Wheel Tests License Python Versions

For more info, please visit the GitHub page of this project.

Basic example

import parameter_checks as pc


@pc.hints.cleanup   # be left with only type-annotations
@pc.hints.enforce   # enforce the lambda but not the types
def div(a: int, b: pc.annotations.Checks[int, lambda b: b != 0]):
    return a / b 

div(1, 1)   # returns 1.0
div(1, 0)   # raises ValueError

As can be seen in this example, this package provides a new type-annotation: pc.annotations.Checks (it also provides pc.annotations.Hooks, see below). Using @pc.hints.enforce on a function will enforce the checks given to those annotations (but not the types). @pc.hints.cleanup would produce the div.__annotations__ of {"a": int, "b": int} in the example above.

Complex example

import parameter_checks as pc


def decision_boundary(fct, parameter, parameter_name, typehint):
    if type(parameter) is not typehint:
        err_str = f"In function {fct}, parameter {parameter_name}={parameter} " \
                  f"is not of type {typehint}!"
        raise TypeError(err_str)
    
    return 3 + 4 * parameter - parameter ** 2


@pc.hints.enforce
def classify(
        x: pc.annotations.Hooks[float, decision_boundary],
        additional_offset: pc.annotations.Checks[float, lambda b: 0 <= b <= 100] = 0.
) -> bool:
    return (x + additional_offset) >= 0
    

if __name__ == '__main__':
    assert classify(1.) is True   # 6.
    assert classify(2.) is True   # 7.
    assert classify(5.) is False   # -2.
    assert classify(5., 2.) is True   # 0.
    
    classify("not a float!")  # raises TypeError
    classify(1., -1.)   # raises ValueError

For additional comments on this example (and much more), visit the GitHub page of this project.

Metadata

Release files for parameter-checks 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for parameter-checks 1.0.0
File Size Uploaded Provenance Actions
parameter-checks-1.0.0.tar.gz 9.3 kB Without provenance Details for parameter-checks-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for parameter-checks 1.0.0
File Interpreter ABI Platform Actions
parameter_checks-1.0.0-py3-none-any.whl Python 3 none any Details for parameter_checks-1.0.0-py3-none-any.whl

Total release size: 14.8 kB

Release files / parameter-checks-1.0.0.tar.gz

Download URL parameter-checks-1.0.0.tar.gz
Size 9.3 kB
Tags Source
SHA-256 checksum
How to use checksums
f09b3043ea45f65376761ec6c1f78ac59695feb39f4e8a14e30d173e9d08c7e1
BLAKE2b-256 checksum
How to use checksums
b90b7a02003923dfa7927f46c56134b52b99e2264edb241282bb9f3acb4e650f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.13

Release files / parameter_checks-1.0.0-py3-none-any.whl

Download URL parameter_checks-1.0.0-py3-none-any.whl
Size 5.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d07ff8a84d45f902a324d50c97351522151e054c9e079b029efeb94450b70eb2
BLAKE2b-256 checksum
How to use checksums
71ffe48678d085ffbca8de01f23df7c6ccf4ffc622aef68e71ddc1428f2cd7d5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.13

Security for parameter-checks 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page