@support_hooks decorator#

support_hooks(cls)

Decorator which adds hooks functionality to a specific class.

skip_hooks(cls)

Context manager (and decorator) which temporary disables hooks for all the methods of a specific class.

suspend_hooks(cls)

Disables all hooks for all the methods of a specific class.

resume_hooks(cls)

Enables all hooks for all the methods of a specific class.

@onetl.hooks.support_hooks.support_hooks#

Decorator which adds hooks functionality to a specific class.

Only methods decorated with slot can be used for connecting hooks.

Adds skip_hooks, suspend_hooks and resume_hooks to the class.

Examples

from onetl.hooks.hook import support_hooks, slot

@support_hooks
class MyClass:
    @slot
    def my_method(self, arg): ...

@MyClass.my_method.hook
def callback(self, arg): ...

MyClass().my_method()  # will execute callback function
onetl.hooks.support_hooks.skip_hooks(cls: type)#

Context manager (and decorator) which temporary disables hooks for all the methods of a specific class.

Examples

@support_hooks
class MyClass:
    @slot
    def my_method(self, arg):
        ...

@MyClass.my_method.hook
def callback(self, arg):
    ...

obj = MyClass()
obj.my_method(1)  # will execute callback(obj, 1)

with MyClass.skip_hooks():
    obj.my_method()  # will NOT execute callback

# running outside the context restores previous behavior
obj.my_method(2)  # will execute callback(obj, 2)
onetl.hooks.support_hooks.suspend_hooks(cls: type) None#

Disables all hooks for all the methods of a specific class.

Examples

@support_hooks
class MyClass:
    @slot
    def my_method(self, arg): ...

@MyClass.my_method.hook
def callback(self, arg): ...

obj = MyClass()
obj.my_method(1)  # will execute callback(obj, 1)

MyClass.suspend_hooks()

obj.my_method(2)  # will NOT execute callback
onetl.hooks.support_hooks.resume_hooks(cls: type) None#

Enables all hooks for all the methods of a specific class.

Examples

@support_hooks
class MyClass:
    @slot
    def my_method(self, arg): ...

@MyClass.my_method.hook
def callback(self, arg): ...

obj = MyClass()

MyClass.suspend_hooks()
obj.my_method(1)  # will NOT execute callback

MyClass.resume_hooks()

obj.my_method(2)  # will execute callback(obj, 2)