How to use the runtype.__init__.ReturnTypeError function in runtype

To help you get started, we’ve selected a few runtype examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github madisonmay / Runtype / runtype / __init__.py View on Github external
def typed_fn(fn, *args, **kwargs):
        return_value = fn(*args, **kwargs)
        if not is_type(return_value, return_type):
            if coerce_type:
                try:
                    return_value = return_type(return_value)
                except Exception:
                    raise ReturnTypeError(return_type, return_value)
            else:
                raise ReturnTypeError(return_type, return_value)
        return return_value
    return typed_fn
github madisonmay / Runtype / runtype / __init__.py View on Github external
def typed_fn(fn, *args, **kwargs):
        return_value = fn(*args, **kwargs)
        if not is_type(return_value, return_type):
            if coerce_type:
                try:
                    return_value = return_type(return_value)
                except Exception:
                    raise ReturnTypeError(return_type, return_value)
            else:
                raise ReturnTypeError(return_type, return_value)
        return return_value
    return typed_fn