ethereum.utils.ensure
Ensure (Assertion) Utilities ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. contents:: Table of Contents :backlinks: none :local:
Introduction
Functions that simplify checking assertions and raising exceptions.
1""" 2Ensure (Assertion) Utilities 3^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 4 5.. contents:: Table of Contents 6 :backlinks: none 7 :local: 8 9Introduction 10------------ 11 12Functions that simplify checking assertions and raising exceptions. 13""" 14 15from typing import Type, Union 16 17 18def ensure( 19 value: bool, exception: Union[Type[BaseException], BaseException] 20) -> None: 21 """ 22 Does nothing if `value` is truthy, otherwise raises the exception returned 23 by `exception_class`. 24 25 Parameters 26 ---------- 27 28 value : 29 Value that should be true. 30 31 exception : 32 Constructor for the exception to raise. 33 """ 34 if value: 35 return 36 raise exception
def
ensure( value: bool, exception: Union[Type[BaseException], BaseException]) -> None:
19def ensure( 20 value: bool, exception: Union[Type[BaseException], BaseException] 21) -> None: 22 """ 23 Does nothing if `value` is truthy, otherwise raises the exception returned 24 by `exception_class`. 25 26 Parameters 27 ---------- 28 29 value : 30 Value that should be true. 31 32 exception : 33 Constructor for the exception to raise. 34 """ 35 if value: 36 return 37 raise exception
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.