omnipy.util.contexts
Context managers and context helper utilities used across Omnipy.
| CLASS | DESCRIPTION |
|---|---|
LastErrorHolder |
Context manager that stores the latest suppressed exception for later chaining. |
PrintExceptionContext |
Context manager that prints and suppresses the first line of an exception. |
| FUNCTION | DESCRIPTION |
|---|---|
hold_and_reset_prev_attrib_value |
Restore an object's attribute to its previous value when the context exits. |
nothing |
Yield a no-op context value. |
setup_and_teardown_callback_context |
Run optional setup, exception, and teardown callbacks around a context block. |
| ATTRIBUTE | DESCRIPTION |
|---|---|
print_exception |
Context manager instance that prints and suppresses the first line of an exception.
|
print_exception
module-attribute
print_exception = PrintExceptionContext()
Context manager instance that prints and suppresses the first line of an exception.
LastErrorHolder
Bases: AbstractContextManager
flowchart BT
omnipy.util.contexts.LastErrorHolder[LastErrorHolder]
click omnipy.util.contexts.LastErrorHolder href "" "omnipy.util.contexts.LastErrorHolder"
Context manager that stores the latest suppressed exception for later chaining.
| METHOD | DESCRIPTION |
|---|---|
__init__ |
|
raise_derived |
Raise an exception, chained from the last captured one when available. |
Source code in src/omnipy/util/contexts.py
__init__
raise_derived
Raise an exception, chained from the last captured one when available.
| PARAMETER | DESCRIPTION |
|---|---|
exc
|
Exception to raise.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
Exception
|
|
Source code in src/omnipy/util/contexts.py
PrintExceptionContext
Bases: AbstractContextManager
flowchart BT
omnipy.util.contexts.PrintExceptionContext[PrintExceptionContext]
click omnipy.util.contexts.PrintExceptionContext href "" "omnipy.util.contexts.PrintExceptionContext"
Context manager that prints and suppresses the first line of an exception.
- Reference Code reference
Source code in src/omnipy/util/contexts.py
hold_and_reset_prev_attrib_value
hold_and_reset_prev_attrib_value(
obj: object, attr_name: str, copy_attr: bool = False
) -> Iterator[None]
Restore an object's attribute to its previous value when the context exits.
| PARAMETER | DESCRIPTION |
|---|---|
obj
|
Object whose attribute should be restored.
TYPE:
|
attr_name
|
Name of the attribute to preserve and restore.
TYPE:
|
copy_attr
|
Whether to deep-copy the original value before storing it.
TYPE:
|
| YIELDS | DESCRIPTION |
|---|---|
None
|
|
Source code in src/omnipy/util/contexts.py
nothing
setup_and_teardown_callback_context
setup_and_teardown_callback_context(
*,
setup_func: Callable[..., _ValT] | None = None,
setup_func_args: tuple[object, ...] = (),
setup_func_kwargs: dict[str, object] = {},
exception_func: Callable[..., None] | None = None,
exception_func_args: tuple[object, ...] = (),
exception_func_kwargs: dict[str, object] = {},
teardown_func: Callable[..., None] | None = None,
teardown_func_args: tuple[object, ...] = (),
teardown_func_kwargs: dict[str, object] = {},
) -> Iterator[_ValT | None]
Run optional setup, exception, and teardown callbacks around a context block.
| PARAMETER | DESCRIPTION |
|---|---|
setup_func
|
Optional callback invoked before entering the context.
TYPE:
|
setup_func_args
|
Positional arguments passed to
TYPE:
|
setup_func_kwargs
|
Keyword arguments passed to
TYPE:
|
exception_func
|
Optional callback invoked if the context raises.
TYPE:
|
exception_func_args
|
Positional arguments passed to
TYPE:
|
exception_func_kwargs
|
Keyword arguments passed to
TYPE:
|
teardown_func
|
Optional callback invoked when leaving the context.
TYPE:
|
teardown_func_args
|
Positional arguments passed to
TYPE:
|
teardown_func_kwargs
|
Keyword arguments passed to
TYPE:
|
| YIELDS | DESCRIPTION |
|---|---|
_ValT | None
|
The value returned by |