Source code for monitorch.gatherer.abstract_gatherer

from abc import ABC, abstractmethod
from functools import wraps


[docs] class AbstractGatherer(ABC): """ An abstract class that parents all gatherers. """ def __init__(self, inspector_state): self.inspector_state = inspector_state @abstractmethod def __call__(self, *args, **kwargs) -> None: """ Callback implementation. """
[docs] @abstractmethod def detach(self) -> None: """ Abstract method to detach from module. Detaches gatherer and all its acompaning preprocessors from module. """ self.inspector_state = None
[docs] @staticmethod def requires_active_inspector_state(fn): @wraps(fn) def wrapper(*args, **kwargs): # # signature wrapper(self, *args, **kwargs) does not behave well with unpacking, namely it starts to scaffold it like this (arg1, (arg2, (arg3, ...))) # instance = args[0] if instance.inspector_state.is_active: fn(*args, **kwargs) return wrapper