Ensure (Assertion) Utilities

Introduction

Functions that simplify checking assertions and raising exceptions.

Module Contents

Functions

ensure

Does nothing if value is truthy, otherwise raises the exception returned

Module Details

ensure

ensure(value: bool, exception: Union[Type[BaseException], BaseException])None

Does nothing if value is truthy, otherwise raises the exception returned by exception_class.

Parameters
  • value – Value that should be true.

  • exception – Constructor for the exception to raise.

def ensure(
    value: bool, exception: Union[Type[BaseException], BaseException]
) -> None:
    if value:
        return
    raise exception