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 collected exceptions are merged and re-raised as a single PrecommitError when the context manager exits. Set raise_exception=False to print the collected messages instead of raising.

>>> 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 PrecommitError exceptions.

property error_messages: tuple[str, ...][source]#

View the collected error messages.