executor#
Collect PrecommitError instances from several executed functions.
- class Executor(raise_exception: bool = True)[source]#
Bases:
AbstractContextManagerExecute functions and collect any
PrecommitErrorexceptions.The
Executoris a context manager that can be used to sequentially execute functions and collect anyPrecommitErrorexceptions they raise. The collected exceptions are merged and re-raised as a newPrecommitErrorwhen the context manager exits.To avoid raising the exceptions, set the
raise_exceptionargument 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: Callable[P, T], *args: args, **kwargs: kwargs) T | None[source]#
Execute a function and collect any
PrecommitErrorexceptions.