TypeCheck Class
- class kwhelp.decorator.TypeCheck(*args: Union[type, Iterable[type]], **kwargs)[source]
Decorator that decorates methods that requires args to match a type specificed in a list
See also
- __init__(*args: Union[type, Iterable[type]], **kwargs)[source]
Constructor
- Parameters
args (type) – One or more types for wrapped function args to match.
- Keyword Arguments
raise_error – (bool, optional): If
True
then aTypeError
will be raised if a validation fails. IfFalse
then an attribute will be set on decorated function namedis_types_valid
indicating if validation status. DefaultTrue
.type_instance_check (bool, optional) – If
True
then args are tested also forisinstance()
if type does not match, rather then just type check. IfFalse
then values willl only be tested as type. DefaultTrue
ftype (DecFuncType, optional) – Type of function that decorator is applied on. Default
DecFuncType.FUNCTION
opt_return (object, optional) – Return value when decorator is invalid. By default an error is rasied when validation fails. If
opt_return
is supplied then it will be return when validation fails and no error will be raised.opt_args_filter (DecArgEnum, optional) – Filters the arguments that are validated. Default
DecArgEnum.ALL
.opt_logger (Union[Logger, LoggerAdapter], optional) – Logger that logs exceptions when validation fails.
- Raises
TypeError – If
types
arg is not a iterable object such as a list or tuple.TypeError – If any arg is not of a type listed in
types
.