typewrap module¶
-
exception
typewrap.
TypeCheckError
¶ Bases:
TypeError
Subclass of TypeError for type checking input or output exceptions.
-
typewrap.
checkInputs
(f: Callable) → Callable¶ Function input type-checking decorator.
Wraps a function with argument type annotations. When function is called, checks input arguments against annotated types.
- Parameters
f – Function with argument type hints to check
- Raises
TypeCheckError – If not isinstance(argValue,argType)
Examples:
>>> @checkInputs >>> def add(a: int, b: int ... return a + b >>> add(1, 2) # Works >>> add(1, 2.0) # Raises TypeCheckError
-
typewrap.
checkOutputs
(f: Callable) → Callable¶ Function output type-checking decorator.
Wraps a function with argument type annotations. When function is called, checks output value type against annotated type.
- Parameters
f – Function with return type hint to check
- Raises
TypeCheckError – If not isinstance(returnValue,returnType)
Examples:
>>> @checkOutputs >>> def add(a, b) -> int: ... return a + b >>> add(1, 2) # Works >>> @checkOutputs >>> def add(a, b) -> str: ... return a + b >>> add(1, 2) # Raises TypeCheckError