util

util.functions

texasholdem.util.functions.check_raise(exc_type)[source]

Decorator that turns a function that returns a bool and message into a function that returns a bool and optionally throws an error.

Injects argument throws (bool): default False.

Example

You can use the decorator like so:

@check_raise(ValueError)
def validate(arg1):
    return False, "test"

validate("arg1")                # will return False
validate("arg1", throws=True)   # will raise ValueError("test")
Parameters:

exc_type (Type[Exception]) – The Exception type to throw.

texasholdem.util.functions.handle(handler, exc_type=<class 'Exception'>)[source]

Decorator that wraps the entire function in a try-except statement that catches the given exc_type and handles it with the given handler.

Parameters:
  • exc_type (Type[Exception]) – The exception type to handle

  • handler – Function that handles the exc_type exception

texasholdem.util.functions.preflight(prerun)[source]

Decorator that runs the given function with the same parameters of the decorated function beforehand.

Parameters:

prerun – Function that runs before the decorated function, takes the same arguments.

texasholdem.util.functions.raise_if(exc, condition)[source]

Throws the given exception if condition is True. Useful to throw errors in lambda statements.

Parameters:
  • exc (Exception) – The exception instance to throw

  • condition (bool) – If true, will raise the given error