def return_as(returntype):
def decorator(func):<EOL><INDENT>def wrapped(*args, **kwargs):<EOL><INDENT>result = func(*args, **kwargs)<EOL>try:<EOL><INDENT>return returntype(result)<EOL><DEDENT>except (TypeError, ValueError) as exc:<EOL><INDENT>exc.args = (<EOL>'<STR_LIT>'.format(<EOL>func.__name__, returntype.__name__, str(exc)),<EOL>)<EOL>raise<EOL><DEDENT><DEDENT>try:<EOL><INDENT>return wraps(func)(wrapped)<EOL><DEDENT>except AttributeError:  <EOL><INDENT>wrapped.__doc__ == func.__doc__<EOL>return wrapped<EOL><DEDENT><DEDENT>return decorator<EOL>
Decorator to cast return of function as the given type

    Parameters
    ----------
    returntype : `type`
        the desired return type of the decorated function