executor#
Collect PrecommitError
instances from several executed functions.
- class Executor(raise_exception: bool = True)[source]#
Bases:
AbstractContextManager
Execute functions and collect any
PrecommitError
exceptions.The
Executor
is a context manager that can be used to sequentially execute functions and collect anyPrecommitError
exceptions they raise. The collected exceptions are merged and re-raised as a newPrecommitError
when the context manager exits.To avoid raising the exceptions, set the
raise_exception
argument toFalse
. The collected exceptions will then be printed to the console instead.>>> def function1() -> None: ... raise PrecommitError("Error message 1") >>> def function2() -> None: ... raise PrecommitError("Error message 2") >>> def function3() -> None: ... >>> >>> with Executor(raise_exception=False) as execute: ... execute(function1) ... execute(function2) ... execute(function3) Error message 1 -------------------- Error message 2
- __call__(function: ~typing.Callable[[~P], ~compwa_policy.utilities.executor.T], *args: ~typing.~P, **kwargs: ~typing.~P) T | None [source]#
Execute a function and collect any
PrecommitError
exceptions.