Skip to main content

A super small package for function input type checking

Project description

Type-Wrap

created by Austin Poor

Build Status PyPI PyPI - Python Version

Super tiny python package for function typechecking.

Installation

Install with pip

$ pip install typewrap

Usage

There's only one function in the package, typeCheck, a decorator function that checks the function input and outputs against the function annotations.

Example:

from typewrap import typeCheck

def add_noChecks(a: int, b: int) -> int:
    """Has annotations but doesn't
    check argument types."""
    return a + b

@typeCheck
def add_checkInputs(a: int, b: int) -> int:
    return a + b

@typeCheck
def add_checkOutputs(a: int, b: int) -> int:
    return float(a+b)

# Unwrapped function with 
# uninforced type annotations
add_noChecks(1,2.0) # No errors


# Wrapped function with bad
# input arguments
add_checkInputs(1,2.0) # Raises TypeError


# Wrapped function with
# bad output type
add_checkOutputs(1,2) # Raises TypeError

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

typewrap-0.1.3.tar.gz (2.0 kB view hashes)

Uploaded Source

Built Distribution

typewrap-0.1.3-py3-none-any.whl (14.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page