datumaro.util.scope#

Functions

on_error_do(callback, *args[, ...])

on_exit_do(callback, *args[, ignore_errors, ...])

scope_add(cm)

scoped(func[, arg_name])

A function decorator, which allows to do actions with the current scope, such as registering error and exit callbacks and context managers.

Classes

Scope()

A context manager that allows to register error and exit callbacks.

class datumaro.util.scope.Scope[source]#

Bases: object

A context manager that allows to register error and exit callbacks.

on_error_do(callback: Callable, *args, kwargs: Dict[str, Any] | None = None, ignore_errors: bool = False)[source]#

Registers a function to be called on scope exit because of an error.

If ignore_errors is True, the errors from this function call will be ignored.

on_exit_do(callback: Callable, *args, kwargs: Dict[str, Any] | None = None, ignore_errors: bool = False)[source]#

Registers a function to be called on scope exit.

add(cm: ContextManager[T]) T[source]#

Enters a context manager and adds it to the exit stack.

Returns: cm.__enter__() result

enable()[source]#
disable()[source]#
close()[source]#
classmethod current() Scope[source]#
as_current()[source]#
datumaro.util.scope.scoped(func, arg_name=None)[source]#

A function decorator, which allows to do actions with the current scope, such as registering error and exit callbacks and context managers.

datumaro.util.scope.on_error_do(callback, *args, ignore_errors=False, kwargs=None)[source]#
datumaro.util.scope.on_exit_do(callback, *args, ignore_errors=False, kwargs=None)[source]#
datumaro.util.scope.scope_add(cm: ContextManager[T]) T[source]#