A super small package for function input type checking
Project description
Type-Wrap
created by Austin Poor
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
Release history Release notifications | RSS feed
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.2.0.tar.gz
(2.2 kB
view hashes)
Built Distribution
typewrap-0.2.0-py3-none-any.whl
(14.7 kB
view hashes)